← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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