← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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