← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. 28
  2. actions and changes
  3. alert()
  4. 44
  5. .js
  6. a pop-up box
  7. 81
  8. Hello, Aman!
  9. let
  10. Welcome, Zoya!
  11. for
  12. in the console
  13. Hello, Zoya!
  14. 79
  15. console.log()
  16. 13
  17. 14
  18. 4
  19. if
  20. Hello, Kabir!
  21. 38
  22. 54
  23. 93
  24. 49
  25. 43
  26. Hi, Arjun!
  27. 26
  28. 9
  29. Hi, Zoya!
  30. 46
  31. 61
  32. 22
  33. let
  34. 41
  35. 28
  36. 19
  37. 74
  38. 47
  39. Hi, Aman!
  40. 28

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