← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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