← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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