← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. <script>
  2. .js
  3. 45
  4. 0
  5. for
  6. 60
  7. let
  8. 89
  9. if
  10. 40
  11. Welcome, Arjun!
  12. 27
  13. 30
  14. 22
  15. 11
  16. 14
  17. 58
  18. let
  19. 12
  20. 63
  21. 13
  22. in the console
  23. actions and changes
  24. 48
  25. 18
  26. 2
  27. console.log()
  28. 16
  29. alert()
  30. 3
  31. 24
  32. 45
  33. 8
  34. 25
  35. 14
  36. 85
  37. 14
  38. 30
  39. Hi, Riya!
  40. 43

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