← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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