← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. 28
  2. 9
  3. Welcome, Zoya!
  4. Welcome, Aman!
  5. let
  6. 40
  7. 20
  8. console.log()
  9. 30
  10. 58
  11. 35
  12. a pop-up box
  13. let
  14. 12
  15. Well done, Meera!
  16. actions and changes
  17. alert()
  18. in the console
  19. 51
  20. 23
  21. .js
  22. 49
  23. 86
  24. Hi, Zoya!
  25. 7
  26. 92
  27. <script>
  28. 47
  29. for
  30. 27
  31. 79
  32. 23
  33. 29
  34. 94
  35. Hi, Arjun!
  36. 58
  37. 49
  38. if
  39. 12
  40. 6

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