← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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