← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. in the console
  2. Well done, Riya!
  3. Hello, Zoya!
  4. 88
  5. <script>
  6. for
  7. 19
  8. console.log()
  9. let
  10. 8
  11. 19
  12. .js
  13. 41
  14. if
  15. 72
  16. 43
  17. Hi, Meera!
  18. Well done, Riya!
  19. Hi, Zoya!
  20. 21
  21. 24
  22. 30
  23. 20
  24. 44
  25. actions and changes
  26. 32
  27. Welcome, Aman!
  28. Hi, Kabir!
  29. 85
  30. 87
  31. 16
  32. alert()
  33. 24
  34. 82
  35. 10
  36. Welcome, Kabir!
  37. 96
  38. 23
  39. Hello, Kabir!
  40. 11

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