← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. 59
  2. 24
  3. in the console
  4. alert()
  5. 3
  6. let
  7. a pop-up box
  8. 83
  9. actions and changes
  10. Hi, Meera!
  11. for
  12. if
  13. 21
  14. <script>
  15. 39
  16. Hello, Riya!
  17. 99
  18. 89
  19. 20
  20. 0
  21. 53
  22. 35
  23. 7
  24. 36
  25. 0
  26. Welcome, Zoya!
  27. 25
  28. 7
  29. Hi, Kabir!
  30. let
  31. 26
  32. 5
  33. 28
  34. 2
  35. 15
  36. Hi, Zoya!
  37. 72
  38. Hello, Aman!
  39. Hello, Riya!
  40. 84

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