Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Challenge: Counting Elements | Section
JavaScript Fundamentals
SectionΒ 1. ChapterΒ 62
single

single

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Β 1. ChapterΒ 62
single

single

Ask AI

expand

Ask AI

ChatGPT

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

some-alt