← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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