← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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