← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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