← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. let
  2. if
  3. 28
  4. in the console
  5. 24
  6. a pop-up box
  7. Hi, Zoya!
  8. Hi, Riya!
  9. 74
  10. for
  11. 70
  12. 13
  13. 66
  14. 16
  15. 25
  16. 89
  17. 30
  18. Hello, Meera!
  19. alert()
  20. 32
  21. actions and changes
  22. Welcome, Riya!
  23. 52
  24. 44
  25. console.log()
  26. .js
  27. 132
  28. 36
  29. 21
  30. 33
  31. 38
  32. 15
  33. 20
  34. 59
  35. Hi, Meera!
  36. 40
  37. 50
  38. 46
  39. 36
  40. 18

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