← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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