← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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