← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. Hello, Kabir!
  2. 17
  3. 67
  4. for
  5. 1
  6. if
  7. 73
  8. 24
  9. alert()
  10. a pop-up box
  11. Well done, Kabir!
  12. 71
  13. console.log()
  14. 43
  15. 20
  16. 16
  17. 99
  18. 7
  19. 80
  20. 66
  21. 33
  22. Hi, Riya!
  23. 25
  24. actions and changes
  25. .js
  26. Welcome, Kabir!
  27. Welcome, Arjun!
  28. 14
  29. Welcome, Arjun!
  30. 38
  31. 94
  32. <script>
  33. 23
  34. 9
  35. 96
  36. 20
  37. 6
  38. 12
  39. Well done, Riya!
  40. 41

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