← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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