← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. 17
  2. Well done, Aman!
  3. .js
  4. Hello, Kabir!
  5. alert()
  6. 7
  7. Hi, Kabir!
  8. 88
  9. 37
  10. let
  11. console.log()
  12. Hello, Meera!
  13. Welcome, Riya!
  14. 19
  15. 1
  16. 36
  17. 22
  18. 39
  19. Well done, Meera!
  20. actions and changes
  21. 45
  22. 18
  23. let
  24. Hi, Aman!
  25. 73
  26. 6
  27. if
  28. in the console
  29. 79
  30. 47
  31. 13
  32. 71
  33. 0
  34. Well done, Riya!
  35. Hello, Aman!
  36. a pop-up box
  37. 33
  38. 57
  39. Welcome, Kabir!
  40. for

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