← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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