← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. 11
  2. .js
  3. 91
  4. 59
  5. <script>
  6. console.log()
  7. 54
  8. let
  9. let
  10. 36
  11. actions and changes
  12. for
  13. 9
  14. 37
  15. 2
  16. 24
  17. 92
  18. 37
  19. 74
  20. alert()
  21. 14
  22. 62
  23. 24
  24. Welcome, Meera!
  25. a pop-up box
  26. 64
  27. 57
  28. if
  29. Well done, Aman!
  30. in the console
  31. Well done, Zoya!
  32. 31
  33. 44
  34. Hi, Zoya!
  35. Welcome, Zoya!
  36. 18
  37. 32
  38. 18
  39. 35
  40. 83

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