← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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