← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. Hello, Meera!
  2. 27
  3. console.log()
  4. a pop-up box
  5. 28
  6. 14
  7. let
  8. actions and changes
  9. 57
  10. 92
  11. alert()
  12. Welcome, Zoya!
  13. 60
  14. let
  15. .js
  16. if
  17. 93
  18. 6
  19. 31
  20. 74
  21. for
  22. 120
  23. 38
  24. 42
  25. 99
  26. Hi, Meera!
  27. 22
  28. <script>
  29. 0
  30. 6
  31. Well done, Meera!
  32. in the console
  33. 70
  34. 71
  35. 32
  36. Hi, Kabir!
  37. 18
  38. 11
  39. 56
  40. 76

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