← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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