← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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