← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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