← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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