← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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