← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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