← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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