← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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