← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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