← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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