← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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