← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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