← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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