← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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