← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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