← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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