← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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