← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. a pop-up box
  2. 6
  3. <script>
  4. 8
  5. 1
  6. 31
  7. .js
  8. in the console
  9. 19
  10. 24
  11. Hi, Riya!
  12. 6
  13. Hello, Arjun!
  14. 53
  15. 23
  16. 10
  17. Welcome, Riya!
  18. 6
  19. 10
  20. 17
  21. 12
  22. for
  23. 51
  24. if
  25. 6
  26. let
  27. let
  28. alert()
  29. 87
  30. 74
  31. 54
  32. 12
  33. 1
  34. 6
  35. 63
  36. 24
  37. 18
  38. 10
  39. 61
  40. 11

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