← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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