← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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