← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. 4
  2. if
  3. 83
  4. 11
  5. console.log()
  6. 87
  7. 26
  8. 68
  9. .js
  10. a pop-up box
  11. alert()
  12. 10
  13. Well done, Riya!
  14. 18
  15. in the console
  16. 71
  17. 92
  18. Hello, Kabir!
  19. let
  20. 16
  21. 0
  22. 15
  23. 21
  24. 19
  25. 43
  26. let
  27. actions and changes
  28. 10
  29. 39
  30. 1
  31. Well done, Arjun!
  32. 132
  33. 6
  34. for
  35. 3
  36. 63
  37. Hi, Arjun!
  38. Welcome, Aman!
  39. Hello, Riya!
  40. Hi, Aman!

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