← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. Well done, Riya!
  2. alert()
  3. 14
  4. 11
  5. actions and changes
  6. 8
  7. for
  8. Hi, Arjun!
  9. 50
  10. Hello, Kabir!
  11. 36
  12. a pop-up box
  13. 13
  14. 93
  15. 44
  16. 17
  17. let
  18. Welcome, Kabir!
  19. let
  20. 84
  21. 58
  22. 28
  23. <script>
  24. 45
  25. 20
  26. 67
  27. .js
  28. 6
  29. 78
  30. if
  31. Welcome, Aman!
  32. 64
  33. Well done, Zoya!
  34. 24
  35. 14
  36. 48
  37. 16
  38. in the console
  39. console.log()
  40. 95

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