← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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