← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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