thecodezone.
The Code Zone
Short steps, at your pace · Free lessons and practice · Member video walkthroughs
Save your next small win.

Checking your account…

17.02 · Math helpers & planning / Practice · 5 min

Distinguish down, up and nearest

One helper was used for every rounding decision. Choose each result deliberately.

Activity 2 of 4 in Math helpers & planning

All courses

JavaScript Basics / 17.02

Distinguish down, up and nearest

Not started

One helper was used for every rounding decision. Choose each result deliberately.

More options
A marker halfway between minus four and minus three rounds down to minus four, and up or nearest to minus three.
Rob’s comic strip · Math helpers & planning

Choose floor, ceil and round for different jobs

Work through 4 focused steps. Read the explanation, type each requested change and check it before moving on. Your own code carries forward.

The mini-lesson opens in a new tab. Your own code carries forward; each step has a focused check and an optional hint.

Start mini-lesson(opens in a new tab)

4 steps · Saved work · Instant feedback

YOUR TURN

Choose each rounding direction

Keep value = -3.5. Use Math.floor for Floor, Math.ceil for Ceil, and Math.round for Round. Keep the three labels and print Floor: -4, Ceil: -3 and Round: -3 on separate lines.

Expected output
Floor: -4
Ceil: -3
Round: -3

Keep the starting inputs. Print these lines in this order, without extra output.

Edit JavaScript, then run it. Check Challenge shows which output checks pass or need a fix. Word wrap is enabled.

Ready to checkRun the checks to see your results here.

Work in VS Code instead

Copy the starter into a file named practice.js in VS Code. If Node.js is installed, open the terminal in that folder and run node practice.js. Compare the output with the task above. Automated challenge checks are available in the browser editor.

Code example
example.jsjavascript · example
const value = -3.5;
console.log("Floor: " + Math.round(value));
console.log("Ceil: " + Math.round(value));
console.log("Round: " + Math.round(value));

Need a nudge?

Picture the negative number line

-4 is below -3.5; -3 is above it. Math.round breaks this half-way tie toward positive infinity.

Replace your editor code?

Your current work will be replaced. Choose Cancel to keep it.

Ready to try it?

Practice in your browser and see your results.

Progress details

Have a question?

Ask the Code Zone community.

Ask a question in The Code Zone (opens in a new tab)

Continue learning

ONE STEP FORWARD

For negative numbers, floor moves toward the more negative integer.