← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. if
  2. 51
  3. let
  4. 93
  5. .js
  6. actions and changes
  7. let
  8. alert()
  9. a pop-up box
  10. for
  11. 3
  12. Well done, Arjun!
  13. Welcome, Kabir!
  14. 8
  15. console.log()
  16. 96
  17. 54
  18. 88
  19. 52
  20. 43
  21. Hello, Zoya!
  22. 16
  23. Welcome, Riya!
  24. 0
  25. 56
  26. 20
  27. 7
  28. 11
  29. Hi, Kabir!
  30. 60
  31. in the console
  32. 70
  33. 74
  34. 28
  35. Well done, Meera!
  36. 39
  37. 65
  38. 6
  39. 61
  40. <script>

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