← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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