← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. in the console
  2. let
  3. <script>
  4. 77
  5. 25
  6. 5
  7. 81
  8. if
  9. actions and changes
  10. .js
  11. 3
  12. Hello, Arjun!
  13. for
  14. alert()
  15. 83
  16. 40
  17. 2
  18. console.log()
  19. 15
  20. 40
  21. 38
  22. 20
  23. 5
  24. 15
  25. 67
  26. a pop-up box
  27. 35
  28. let
  29. Hi, Riya!
  30. 54
  31. 22
  32. 82
  33. 63
  34. 0
  35. 31
  36. 32
  37. 46
  38. 52
  39. 2
  40. 18

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