← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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