Closures & Scope

Saved Values

Saved Values

Closures are often used to split setup from use. The outer function receives a value once, and the returned function applies that value to later inputs.

This pattern keeps repeated configuration out of every call. It also makes it harder to accidentally use a global value that belongs to a different calculation.

Your task: Complete makeDiscount so it receives a percentage as a whole number. It should return a function that receives a price and returns the discounted price.

Free with a JS Exercises account

Sign in to start coding, run your solution, and keep your progress saved for later. No payment needed.

By continuing, you agree to our Terms and Privacy Policy. We'll send occasional product updates and news. You can unsubscribe anytime.

Saved Values

Closures are often used to split setup from use. The outer function receives a value once, and the returned function applies that value to later inputs.

This pattern keeps repeated configuration out of every call. It also makes it harder to accidentally use a global value that belongs to a different calculation.

Your task: Complete makeDiscount so it receives a percentage as a whole number. It should return a function that receives a price and returns the discounted price.

Free with a JS Exercises account

Sign in to start coding, run your solution, and keep your progress saved for later. No payment needed.

By continuing, you agree to our Terms and Privacy Policy. We'll send occasional product updates and news. You can unsubscribe anytime.

Console

Run code to see output.