← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. 17
  2. let
  3. 20
  4. 44
  5. actions and changes
  6. alert()
  7. console.log()
  8. 45
  9. 72
  10. 50
  11. in the console
  12. for
  13. .js
  14. a pop-up box
  15. <script>
  16. 31
  17. let
  18. 43
  19. 5
  20. 2
  21. 53
  22. 52
  23. 32
  24. 9
  25. Well done, Riya!
  26. 28
  27. 63
  28. 6
  29. 67
  30. 37
  31. 59
  32. if
  33. 69
  34. 16
  35. 39
  36. Welcome, Meera!
  37. Hello, Kabir!
  38. Hi, Meera!
  39. Well done, Arjun!
  40. 79

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