← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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