← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. .js
  2. console.log()
  3. 16
  4. actions and changes
  5. for
  6. Hi, Riya!
  7. a pop-up box
  8. 13
  9. 27
  10. 16
  11. 23
  12. in the console
  13. 24
  14. 3
  15. 120
  16. let
  17. 18
  18. 61
  19. 89
  20. 76
  21. 10
  22. alert()
  23. 33
  24. 71
  25. 144
  26. if
  27. 1
  28. 87
  29. 52
  30. 6
  31. 11
  32. Well done, Zoya!
  33. 42
  34. Welcome, Meera!
  35. 3
  36. 56
  37. 23
  38. 20
  39. 27
  40. 23

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