← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

HTML and CSS lesson 25: JavaScript basics · Set 268 · 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.⚡ Which JavaScript word shows a pop-up box? (a) if (b) console.log() (c) alert() (d) let
  2. 2.⚡ Which JavaScript word writes in the console? (a) console.log() (b) let (c) alert() (d) if
  3. 3.⚡ What does this code print? (Look at the quotes!)
    let x = "9";
    let y = 1;
    console.log(x + y);
    (a) 91 (b) Error (c) 10
  4. 4.⚡ Which word makes a new variable? (a) put (b) give (c) make (d) let
  5. 5.⚡ What does alert() show? (a) a table (b) a pop-up box (c) a new tab (d) a picture
  6. 6.⚡ Which JavaScript word repeats code? (a) let (b) alert() (c) for (d) console.log()
  7. 7.⚡ 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
  8. 8.⚡ What number does this code print?
    let apples = 7;
    apples = apples + 17;
    apples = apples - 2;
    console.log(apples);
  9. 9.⚡ What number does this code print?
    let a = 15;
    let b = 9;
    console.log(a - b);
  10. 10.⚡ What number does this code print?
    let apples = 16;
    apples = apples + 12;
    apples = apples - 15;
    console.log(apples);
  11. 11.⚡ What number does this code print?
    let a = 32;
    let b = 26;
    console.log(a + b);
  12. 12.⚡ What does this code show?
    let name = "Meera";
    alert("Hello, " + name + "!");
    (a) Hello, Meera! (b) Hello, name! (c) Meera (d) name
  13. 13.⚡ What does this code show?
    let name = "Riya";
    alert("Well done, " + name + "!");
    (a) Well done, name! (b) name (c) Riya (d) Well done, Riya!
  14. 14.⚡ What number does this code print?
    let score = 17;
    score = score + 12;
    score = score - 5;
    console.log(score);
  15. 15.⚡ 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
  16. 16.⚡ 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
  17. 17.⚡ What does this code show?
    let name = "Riya";
    alert("Hi, " + name + "!");
    (a) Hi, name! (b) Hi, Riya! (c) Riya (d) name
  18. 18.⚡ What number does this code print?
    let runs = 24;
    runs = runs + 11;
    runs = runs - 13;
    console.log(runs);
  19. 19.⚡ Which tag holds JavaScript in a page? (a) <style> (b) <js> (c) <script> (d) <code>
  20. 20.⚡ What number does this code print?
    let marks = 10;
    marks = marks + 2;
    marks = marks - 8;
    console.log(marks);
  21. 21.⚡ What does JavaScript add to a web page? (a) the page title (b) the domain name (c) only colours (d) actions and changes
  22. 22.⚡ What number does this code print?
    let a = 37;
    let b = 10;
    console.log(a + b);
  23. 23.⚡ What does this code show?
    let name = "Arjun";
    alert("Hi, " + name + "!");
    (a) Hi, Arjun! (b) Arjun (c) Hi, name! (d) name
  24. 24.⚡ What number does this code print?
    let a = 45;
    let b = 38;
    console.log(a - b);
  25. 25.⚡ What number does this code print?
    let a = 6;
    let b = 4;
    console.log(a * b);
  26. 26.⚡ What number does this code print?
    let a = 8;
    let b = 10;
    console.log(a * b);
  27. 27.⚡ What does this code print? (Look at the quotes!)
    let x = "7";
    let y = 2;
    console.log(x + y);
    (a) Error (b) 9 (c) 72
  28. 28.⚡ Which JavaScript word runs code when true? (a) let (b) alert() (c) if (d) console.log()
  29. 29.⚡ What does this code show?
    let name = "Arjun";
    console.log("Hi, " + name + "!");
    (a) Arjun (b) Hi, Arjun! (c) name (d) Hi, name!
  30. 30.⚡ What number does this code print?
    let a = 8;
    let b = 3;
    console.log(a - b);
  31. 31.⚡ What number does this code print?
    let a = 28;
    let b = 23;
    console.log(a + b);
  32. 32.⚡ What number does this code print?
    let a = 29;
    let b = 16;
    console.log(a - b);
  33. 33.⚡ What number does this code print?
    let a = 18;
    let b = 5;
    console.log(a + b);
  34. 34.⚡ What number does this code print?
    let apples = 24;
    apples = apples + 17;
    apples = apples - 16;
    console.log(apples);
  35. 35.⚡ What number does this code print?
    let runs = 13;
    runs = runs + 13;
    runs = runs - 22;
    console.log(runs);
  36. 36.⚡ What number does this code print?
    let a = 18;
    let b = 9;
    console.log(a - b);
  37. 37.⚡ What does this code print? (Look at the quotes!)
    let x = "7";
    let y = 4;
    console.log(x + y);
    (a) 11 (b) 74 (c) Error
  38. 38.⚡ Which JavaScript word makes a new variable? (a) for (b) if (c) let (d) console.log()
  39. 39.⚡ What does this code print? (Look at the quotes!)
    let x = "2";
    let y = 1;
    console.log(x + y);
    (a) 3 (b) 21 (c) Error
  40. 40.⚡ What does this code show?
    let name = "Zoya";
    console.log("Hi, " + name + "!");
    (a) Hi, Zoya! (b) Hi, name! (c) name (d) Zoya

Answer key

  1. alert()
  2. console.log()
  3. 91
  4. let
  5. a pop-up box
  6. for
  7. 19
  8. 22
  9. 6
  10. 13
  11. 58
  12. Hello, Meera!
  13. Well done, Riya!
  14. 24
  15. 58
  16. in the console
  17. Hi, Riya!
  18. 22
  19. <script>
  20. 4
  21. actions and changes
  22. 47
  23. Hi, Arjun!
  24. 7
  25. 24
  26. 80
  27. 72
  28. if
  29. Hi, Arjun!
  30. 5
  31. 51
  32. 13
  33. 23
  34. 25
  35. 4
  36. 9
  37. 74
  38. let
  39. 21
  40. Hi, Zoya!

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