← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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