← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. 36
  2. alert()
  3. console.log()
  4. let
  5. 35
  6. 16
  7. let
  8. Hi, Meera!
  9. 32
  10. Welcome, Zoya!
  11. Hello, Zoya!
  12. 13
  13. 15
  14. Well done, Meera!
  15. 30
  16. 4
  17. <script>
  18. in the console
  19. 9
  20. 16
  21. 4
  22. 4
  23. actions and changes
  24. 99
  25. 18
  26. 84
  27. 31
  28. 54
  29. 20
  30. Well done, Riya!
  31. Hello, Meera!
  32. a pop-up box
  33. 25
  34. 8
  35. 81
  36. for
  37. if
  38. 21
  39. 11
  40. 24

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