← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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