← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. 28
  2. actions and changes
  3. 1
  4. Hello, Arjun!
  5. 82
  6. 2
  7. let
  8. 34
  9. 33
  10. a pop-up box
  11. Welcome, Kabir!
  12. 3
  13. let
  14. in the console
  15. alert()
  16. for
  17. if
  18. <script>
  19. 88
  20. 46
  21. 10
  22. console.log()
  23. 37
  24. 25
  25. 56
  26. Hello, Aman!
  27. 15
  28. 7
  29. Hello, Aman!
  30. 20
  31. 25
  32. 11
  33. Hi, Aman!
  34. 65
  35. 30
  36. 73
  37. 4
  38. 24
  39. 41
  40. 77

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