← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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