← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

HTML and CSS lesson 25: JavaScript basics · Set 49 · 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.⚡ 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
  2. 2.⚡ What does this code print? (Look at the quotes!)
    let x = "1";
    let y = 6;
    console.log(x + y);
    (a) 16 (b) Error (c) 7
  3. 3.⚡ What number does this code print?
    let a = 4;
    let b = 9;
    console.log(a * b);
  4. 4.⚡ What number does this code print?
    let marks = 20;
    marks = marks + 12;
    marks = marks - 19;
    console.log(marks);
  5. 5.⚡ 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
  6. 6.⚡ What does this code print? (Look at the quotes!)
    let x = "7";
    let y = 2;
    console.log(x + y);
    (a) 72 (b) 9 (c) Error
  7. 7.⚡ Which word makes a new variable? (a) let (b) put (c) make (d) give
  8. 8.⚡ What does this code show?
    let name = "Meera";
    alert("Hi, " + name + "!");
    (a) name (b) Hi, name! (c) Hi, Meera! (d) Meera
  9. 9.⚡ What does this code show?
    let name = "Aman";
    alert("Welcome, " + name + "!");
    (a) Welcome, name! (b) Welcome, Aman! (c) name (d) Aman
  10. 10.⚡ What number does this code print?
    let books = 9;
    books = books + 6;
    books = books - 4;
    console.log(books);
  11. 11.⚡ What number does this code print?
    let a = 2;
    let b = 5;
    console.log(a * b);
  12. 12.⚡ What number does this code print?
    let a = 10;
    let b = 7;
    console.log(a - b);
  13. 13.⚡ Which JavaScript word shows a pop-up box? (a) alert() (b) console.log() (c) for (d) let
  14. 14.⚡ What does this code print? (Look at the quotes!)
    let x = "2";
    let y = 2;
    console.log(x + y);
    (a) 4 (b) Error (c) 22
  15. 15.⚡ What does this code print? (Look at the quotes!)
    let x = "9";
    let y = 6;
    console.log(x + y);
    (a) 96 (b) 15 (c) Error
  16. 16.⚡ What number does this code print?
    let books = 19;
    books = books + 14;
    books = books - 26;
    console.log(books);
  17. 17.⚡ What does this code print? (Look at the quotes!)
    let x = "3";
    let y = 4;
    console.log(x + y);
    (a) 7 (b) 34 (c) Error
  18. 18.⚡ What does this code show?
    let name = "Meera";
    console.log("Hello, " + name + "!");
    (a) Hello, Meera! (b) Hello, name! (c) name (d) Meera
  19. 19.⚡ What number does this code print?
    let score = 10;
    score = score + 15;
    score = score - 21;
    console.log(score);
  20. 20.⚡ What does this code print? (Look at the quotes!)
    let x = "5";
    let y = 8;
    console.log(x + y);
    (a) 58 (b) Error (c) 13
  21. 21.⚡ What does this code print? (Look at the quotes!)
    let x = "1";
    let y = 1;
    console.log(x + y);
    (a) 2 (b) 11 (c) Error
  22. 22.⚡ What number does this code print?
    let marks = 15;
    marks = marks + 14;
    marks = marks - 27;
    console.log(marks);
  23. 23.⚡ What number does this code print?
    let runs = 27;
    runs = runs + 13;
    runs = runs - 32;
    console.log(runs);
  24. 24.⚡ What number does this code print?
    let a = 18;
    let b = 18;
    console.log(a - b);
  25. 25.⚡ What number does this code print?
    let score = 13;
    score = score + 9;
    score = score - 10;
    console.log(score);
  26. 26.⚡ What does this code show?
    let name = "Kabir";
    console.log("Hello, " + name + "!");
    (a) Hello, name! (b) Hello, Kabir! (c) name (d) Kabir
  27. 27.⚡ Which JavaScript word writes in the console? (a) if (b) for (c) console.log() (d) alert()
  28. 28.⚡ Which JavaScript word makes a new variable? (a) alert() (b) if (c) let (d) for
  29. 29.⚡ What number does this code print?
    let a = 6;
    let b = 8;
    console.log(a * b);
  30. 30.⚡ What does this code show?
    let name = "Aman";
    console.log("Hello, " + name + "!");
    (a) name (b) Hello, Aman! (c) Aman (d) Hello, name!
  31. 31.⚡ What does alert() show? (a) a picture (b) a table (c) a new tab (d) a pop-up box
  32. 32.⚡ What number does this code print?
    let a = 45;
    let b = 28;
    console.log(a - b);
  33. 33.⚡ What does JavaScript add to a web page? (a) only colours (b) actions and changes (c) the domain name (d) the page title
  34. 34.⚡ What does this code show?
    let name = "Arjun";
    console.log("Welcome, " + name + "!");
    (a) name (b) Welcome, name! (c) Welcome, Arjun! (d) Arjun
  35. 35.⚡ Which tag holds JavaScript in a page? (a) <code> (b) <js> (c) <script> (d) <style>
  36. 36.⚡ Which JavaScript word runs code when true? (a) let (b) alert() (c) if (d) console.log()
  37. 37.⚡ What number does this code print?
    let books = 18;
    books = books + 18;
    books = books - 7;
    console.log(books);
  38. 38.⚡ Which JavaScript word repeats code? (a) for (b) let (c) console.log() (d) alert()
  39. 39.⚡ What number does this code print?
    let a = 42;
    let b = 27;
    console.log(a + b);
  40. 40.⚡ What does this code show?
    let name = "Aman";
    alert("Hello, " + name + "!");
    (a) Hello, name! (b) name (c) Hello, Aman! (d) Aman

Answer key

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

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