← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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