← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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