← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. 92
  2. 57
  3. .js
  4. for
  5. alert()
  6. let
  7. 4
  8. 40
  9. 2
  10. Well done, Meera!
  11. console.log()
  12. 88
  13. if
  14. actions and changes
  15. 41
  16. Hi, Zoya!
  17. 53
  18. 6
  19. 50
  20. in the console
  21. Welcome, Aman!
  22. 55
  23. 5
  24. 6
  25. 11
  26. 5
  27. 68
  28. 22
  29. <script>
  30. Hello, Aman!
  31. 25
  32. 65
  33. 13
  34. 13
  35. 49
  36. 74
  37. let
  38. 15
  39. Hello, Arjun!
  40. 38

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