← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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