← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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