← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. Welcome, Riya!
  2. .js
  3. 19
  4. 11
  5. 21
  6. a pop-up box
  7. for
  8. 21
  9. let
  10. 22
  11. Welcome, Kabir!
  12. console.log()
  13. 45
  14. in the console
  15. 66
  16. Hello, Riya!
  17. 36
  18. 4
  19. Well done, Aman!
  20. 89
  21. Hi, Kabir!
  22. 72
  23. 23
  24. 77
  25. if
  26. 1
  27. 7
  28. 69
  29. 98
  30. 28
  31. 41
  32. 11
  33. 31
  34. alert()
  35. Hello, Aman!
  36. 17
  37. 35
  38. <script>
  39. 28
  40. 8

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