← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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