← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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