← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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