← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. in the console
  2. <script>
  3. let
  4. 22
  5. 24
  6. console.log()
  7. alert()
  8. let
  9. 4
  10. 4
  11. 31
  12. a pop-up box
  13. actions and changes
  14. 43
  15. 72
  16. for
  17. 65
  18. 57
  19. if
  20. 12
  21. 55
  22. 52
  23. 66
  24. 75
  25. 23
  26. Well done, Meera!
  27. 41
  28. .js
  29. 30
  30. 22
  31. Hi, Meera!
  32. 23
  33. Well done, Arjun!
  34. Hello, Riya!
  35. 16
  36. 45
  37. Well done, Aman!
  38. Welcome, Riya!
  39. 83
  40. 3

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