← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. 13
  2. 27
  3. 16
  4. for
  5. 24
  6. 13
  7. 121
  8. let
  9. 55
  10. 9
  11. 28
  12. console.log()
  13. 8
  14. 19
  15. 32
  16. Hello, Aman!
  17. 52
  18. Hi, Zoya!
  19. alert()
  20. 20
  21. 81
  22. 3
  23. 10
  24. Welcome, Aman!
  25. 59
  26. Hi, Aman!
  27. 17
  28. <script>
  29. actions and changes
  30. 72
  31. in the console
  32. 26
  33. 41
  34. Welcome, Meera!
  35. if
  36. let
  37. Well done, Arjun!
  38. 72
  39. 15
  40. .js

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