← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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