← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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