← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. Hi, Aman!
  2. if
  3. for
  4. <script>
  5. actions and changes
  6. let
  7. 91
  8. 34
  9. alert()
  10. 95
  11. 13
  12. 20
  13. Well done, Zoya!
  14. 53
  15. 20
  16. in the console
  17. 5
  18. 48
  19. 39
  20. 17
  21. 21
  22. 35
  23. 47
  24. 70
  25. Hello, Arjun!
  26. 2
  27. Well done, Riya!
  28. Well done, Arjun!
  29. 24
  30. Hi, Kabir!
  31. Hi, Arjun!
  32. 36
  33. 77
  34. 49
  35. .js
  36. console.log()
  37. Hi, Meera!
  38. 32
  39. 16
  40. 19

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