← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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