← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

HTML and CSS lesson 25: JavaScript basics · Set 954 · 40 questions
TalentJR

Code tip (Line by line): let x = 5; makes a variable x holding 5; x = x + 2; changes it to 7. console.log(…) writes in the console; alert(…) shows a pop-up box. Text in quotes + anything = joined text: "5" + 3 → "53".

NameDateTime takenScore ___ / 40
  1. 1.⚡ A JavaScript file usually ends with which extension? (a) .jpg (b) .css (c) .js (d) .html
  2. 2.⚡ Which word makes a new variable? (a) give (b) let (c) put (d) make
  3. 3.⚡ What does this code print? (Look at the quotes!)
    let x = "2";
    let y = 3;
    console.log(x + y);
    (a) 23 (b) 5 (c) Error
  4. 4.⚡ Which JavaScript word repeats code? (a) let (b) for (c) if (d) alert()
  5. 5.⚡ Which JavaScript word makes a new variable? (a) console.log() (b) for (c) let (d) if
  6. 6.⚡ Which tag holds JavaScript in a page? (a) <style> (b) <js> (c) <script> (d) <code>
  7. 7.⚡ What number does this code print?
    let a = 31;
    let b = 20;
    console.log(a - b);
  8. 8.⚡ What does JavaScript add to a web page? (a) the page title (b) the domain name (c) actions and changes (d) only colours
  9. 9.⚡ What number does this code print?
    let a = 4;
    let b = 6;
    console.log(a * b);
  10. 10.⚡ What number does this code print?
    let a = 9;
    let b = 3;
    console.log(a * b);
  11. 11.⚡ What does this code print? (Look at the quotes!)
    let x = "4";
    let y = 4;
    console.log(x + y);
    (a) Error (b) 44 (c) 8
  12. 12.⚡ What number does this code print?
    let marks = 16;
    marks = marks + 8;
    marks = marks - 11;
    console.log(marks);
  13. 13.⚡ Which JavaScript word runs code when true? (a) alert() (b) let (c) for (d) if
  14. 14.⚡ What does this code show?
    let name = "Meera";
    alert("Hi, " + name + "!");
    (a) name (b) Hi, Meera! (c) Meera (d) Hi, name!
  15. 15.⚡ What number does this code print?
    let a = 12;
    let b = 12;
    console.log(a * b);
  16. 16.⚡ What number does this code print?
    let apples = 28;
    apples = apples + 15;
    apples = apples - 37;
    console.log(apples);
  17. 17.⚡ Which JavaScript word shows a pop-up box? (a) alert() (b) console.log() (c) if (d) for
  18. 18.⚡ Where does console.log() show its output? (a) on the printer (b) in the address bar (c) in the console (d) on the title bar
  19. 19.⚡ What does this code print? (Look at the quotes!)
    let x = "1";
    let y = 5;
    console.log(x + y);
    (a) 6 (b) Error (c) 15
  20. 20.⚡ What does this code show?
    let name = "Zoya";
    console.log("Well done, " + name + "!");
    (a) name (b) Zoya (c) Well done, Zoya! (d) Well done, name!
  21. 21.⚡ Which JavaScript word writes in the console? (a) alert() (b) console.log() (c) let (d) for
  22. 22.⚡ What number does this code print?
    let a = 53;
    let b = 7;
    console.log(a + b);
  23. 23.⚡ What does this code print? (Look at the quotes!)
    let x = "7";
    let y = 7;
    console.log(x + y);
    (a) 14 (b) 77 (c) Error
  24. 24.⚡ What does this code print? (Look at the quotes!)
    let x = "8";
    let y = 1;
    console.log(x + y);
    (a) 81 (b) 9 (c) Error
  25. 25.⚡ What number does this code print?
    let a = 45;
    let b = 1;
    console.log(a - b);
  26. 26.⚡ What number does this code print?
    let score = 29;
    score = score + 15;
    score = score - 13;
    console.log(score);
  27. 27.⚡ What does this code show?
    let name = "Riya";
    alert("Welcome, " + name + "!");
    (a) Riya (b) Welcome, Riya! (c) Welcome, name! (d) name
  28. 28.⚡ What does this code print? (Look at the quotes!)
    let x = "3";
    let y = 2;
    console.log(x + y);
    (a) 32 (b) Error (c) 5
  29. 29.⚡ What does this code print? (Look at the quotes!)
    let x = "2";
    let y = 5;
    console.log(x + y);
    (a) 25 (b) Error (c) 7
  30. 30.⚡ What number does this code print?
    let a = 2;
    let b = 10;
    console.log(a * b);
  31. 31.⚡ What does this code show?
    let name = "Meera";
    alert("Welcome, " + name + "!");
    (a) Welcome, name! (b) name (c) Meera (d) Welcome, Meera!
  32. 32.⚡ What number does this code print?
    let a = 30;
    let b = 36;
    console.log(a + b);
  33. 33.⚡ What does this code show?
    let name = "Riya";
    alert("Hi, " + name + "!");
    (a) Riya (b) Hi, name! (c) name (d) Hi, Riya!
  34. 34.⚡ What number does this code print?
    let a = 5;
    let b = 19;
    console.log(a + b);
  35. 35.⚡ What does alert() show? (a) a table (b) a new tab (c) a pop-up box (d) a picture
  36. 36.⚡ What number does this code print?
    let a = 52;
    let b = 9;
    console.log(a + b);
  37. 37.⚡ What number does this code print?
    let apples = 25;
    apples = apples + 8;
    apples = apples - 19;
    console.log(apples);
  38. 38.⚡ What does this code show?
    let name = "Kabir";
    console.log("Hi, " + name + "!");
    (a) Hi, name! (b) name (c) Kabir (d) Hi, Kabir!
  39. 39.⚡ What does this code print? (Look at the quotes!)
    let x = "2";
    let y = 6;
    console.log(x + y);
    (a) Error (b) 8 (c) 26
  40. 40.⚡ What number does this code print?
    let marks = 12;
    marks = marks + 11;
    marks = marks - 9;
    console.log(marks);

Answer key

  1. .js
  2. let
  3. 23
  4. for
  5. let
  6. <script>
  7. 11
  8. actions and changes
  9. 24
  10. 27
  11. 44
  12. 13
  13. if
  14. Hi, Meera!
  15. 144
  16. 6
  17. alert()
  18. in the console
  19. 15
  20. Well done, Zoya!
  21. console.log()
  22. 60
  23. 77
  24. 81
  25. 44
  26. 31
  27. Welcome, Riya!
  28. 32
  29. 25
  30. 20
  31. Welcome, Meera!
  32. 66
  33. Hi, Riya!
  34. 24
  35. a pop-up box
  36. 61
  37. 14
  38. Hi, Kabir!
  39. 26
  40. 14

Free html and css lessons, practice and worksheets at talentjr.in/html-css-for-kids