← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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