← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. 92
  2. Well done, Riya!
  3. 55
  4. 13
  5. actions and changes
  6. in the console
  7. 82
  8. a pop-up box
  9. let
  10. for
  11. Hello, Kabir!
  12. 132
  13. 34
  14. let
  15. alert()
  16. 30
  17. 12
  18. Welcome, Zoya!
  19. Well done, Riya!
  20. Hi, Riya!
  21. 33
  22. 40
  23. 76
  24. console.log()
  25. 11
  26. Hi, Zoya!
  27. .js
  28. Well done, Arjun!
  29. 33
  30. 93
  31. 96
  32. 18
  33. <script>
  34. 58
  35. 5
  36. 52
  37. 26
  38. 12
  39. Welcome, Aman!
  40. 31

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