← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. 63
  2. for
  3. 19
  4. 91
  5. console.log()
  6. Hi, Zoya!
  7. .js
  8. 17
  9. 21
  10. let
  11. let
  12. 52
  13. if
  14. 20
  15. Hello, Zoya!
  16. Welcome, Meera!
  17. 17
  18. 51
  19. Hello, Riya!
  20. a pop-up box
  21. <script>
  22. Hi, Riya!
  23. 85
  24. 88
  25. 24
  26. in the console
  27. 15
  28. 3
  29. Hi, Aman!
  30. alert()
  31. 53
  32. 21
  33. 57
  34. 66
  35. 45
  36. 55
  37. 7
  38. actions and changes
  39. 94
  40. 97

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