← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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