← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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