← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. <script>
  2. 13
  3. 98
  4. 22
  5. 95
  6. 81
  7. let
  8. if
  9. 7
  10. 16
  11. 32
  12. 57
  13. 26
  14. .js
  15. 26
  16. 21
  17. 12
  18. 53
  19. Well done, Riya!
  20. 10
  21. for
  22. 10
  23. 63
  24. 58
  25. 52
  26. 97
  27. alert()
  28. console.log()
  29. 38
  30. Hello, Zoya!
  31. in the console
  32. actions and changes
  33. 32
  34. let
  35. 14
  36. 5
  37. Hi, Arjun!
  38. Hi, Riya!
  39. 86
  40. Well done, Aman!

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