← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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