← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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