← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. 24
  2. if
  3. 4
  4. 82
  5. 16
  6. 20
  7. 4
  8. 15
  9. 11
  10. 41
  11. 26
  12. 9
  13. 42
  14. 37
  15. 44
  16. let
  17. 91
  18. 10
  19. Welcome, Riya!
  20. <script>
  21. in the console
  22. 1
  23. actions and changes
  24. 16
  25. a pop-up box
  26. Hi, Kabir!
  27. 18
  28. for
  29. 83
  30. 65
  31. alert()
  32. console.log()
  33. 28
  34. 43
  35. 16
  36. 42
  37. 26
  38. 96
  39. .js
  40. 53

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