← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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