← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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