← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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