← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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