← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. Welcome, Aman!
  2. <script>
  3. a pop-up box
  4. 47
  5. let
  6. console.log()
  7. 5
  8. 44
  9. 13
  10. if
  11. 19
  12. 1
  13. actions and changes
  14. 15
  15. 75
  16. alert()
  17. Well done, Aman!
  18. 9
  19. .js
  20. for
  21. 55
  22. in the console
  23. let
  24. 23
  25. 21
  26. 47
  27. 99
  28. 36
  29. 69
  30. 19
  31. 77
  32. Hello, Riya!
  33. 14
  34. 52
  35. 81
  36. Welcome, Arjun!
  37. 74
  38. 8
  39. 76
  40. 14

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