← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. 21
  2. for
  3. 30
  4. let
  5. console.log()
  6. Hello, Kabir!
  7. 68
  8. 47
  9. 40
  10. if
  11. 44
  12. 0
  13. <script>
  14. 99
  15. Welcome, Zoya!
  16. 3
  17. 92
  18. 55
  19. 6
  20. Well done, Riya!
  21. 31
  22. in the console
  23. 27
  24. 47
  25. 12
  26. alert()
  27. let
  28. .js
  29. 13
  30. 14
  31. 11
  32. 36
  33. 108
  34. 20
  35. Well done, Arjun!
  36. Hello, Meera!
  37. 24
  38. 3
  39. 4
  40. 39

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