← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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