← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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