← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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