← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. in the console
  2. 19
  3. console.log()
  4. 22
  5. Hello, Meera!
  6. .js
  7. actions and changes
  8. let
  9. 14
  10. 33
  11. 2
  12. 51
  13. Hi, Riya!
  14. for
  15. 82
  16. 30
  17. alert()
  18. 33
  19. 7
  20. 5
  21. 23
  22. 45
  23. <script>
  24. 24
  25. 25
  26. 73
  27. if
  28. 43
  29. Hi, Arjun!
  30. 53
  31. 34
  32. 39
  33. 29
  34. 11
  35. 57
  36. Welcome, Aman!
  37. 49
  38. 48
  39. 27
  40. let

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