← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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