← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. 56
  2. 23
  3. Hello, Riya!
  4. 61
  5. 0
  6. 21
  7. let
  8. let
  9. console.log()
  10. 14
  11. Hi, Arjun!
  12. 47
  13. 96
  14. 85
  15. 63
  16. Well done, Meera!
  17. Well done, Aman!
  18. 17
  19. 76
  20. 53
  21. in the console
  22. a pop-up box
  23. 93
  24. 33
  25. 33
  26. Hi, Meera!
  27. 44
  28. 45
  29. 17
  30. actions and changes
  31. alert()
  32. 59
  33. 64
  34. 10
  35. .js
  36. 14
  37. 60
  38. 34
  39. 19
  40. 12

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