← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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