← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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