Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Challenge: Counting Elements | Exploring Arrays
Introduction to JavaScript

bookChallenge: Counting Elements

Task

Swipe to start coding

You are given an array called fruitBasket that contains several fruit names.

Your tasks:

  • Create a variable named numberOfFruits and assign it the length of the fruitBasket array.
  • Use an if...else statement to generate a message:
  • If there are 3 or fewer fruits, return: "We have a small fruit basket with [number] fruits!"
  • If there are more than 3 fruits, return: "We have a big fruit basket with [number] fruits!"
  • Use the numberOfFruits variable inside the message.
  • Do NOT hardcode the number.

Solution

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 5. ChapterΒ 9
single

single

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

close

bookChallenge: Counting Elements

Swipe to show menu

Task

Swipe to start coding

You are given an array called fruitBasket that contains several fruit names.

Your tasks:

  • Create a variable named numberOfFruits and assign it the length of the fruitBasket array.
  • Use an if...else statement to generate a message:
  • If there are 3 or fewer fruits, return: "We have a small fruit basket with [number] fruits!"
  • If there are more than 3 fruits, return: "We have a big fruit basket with [number] fruits!"
  • Use the numberOfFruits variable inside the message.
  • Do NOT hardcode the number.

Solution

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 5. ChapterΒ 9
single

single

some-alt