← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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