← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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