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.

  1. Create a variable named numberOfFruits and assign it the length of the fruitBasket array.
  2. Use an if...else statement to:
    • Print "We have a small fruit basket with [number] fruits!" if there are 3 or fewer fruits.
    • Print "We have a big fruit basket with [number] fruits!" if there are more than 3 fruits.
  3. Make sure you use the numberOfFruits variable in your console messages. Do not hardcode any numbers.

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

Awesome!

Completion rate improved to 1.33

bookChallenge: Counting Elements

Swipe to show menu

Task

Swipe to start coding

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

  1. Create a variable named numberOfFruits and assign it the length of the fruitBasket array.
  2. Use an if...else statement to:
    • Print "We have a small fruit basket with [number] fruits!" if there are 3 or fewer fruits.
    • Print "We have a big fruit basket with [number] fruits!" if there are more than 3 fruits.
  3. Make sure you use the numberOfFruits variable in your console messages. Do not hardcode any numbers.

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