← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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