← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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