← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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