← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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