← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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