Instructions pass but code fails to run. Can anyone help me understand why please.
This is due to ES6 new concise arrow function.
You don’t need to use return. Or you can, but then you need to add { }
.
Here’s an example:
// ES5
function volumeOfSphere(diameter) {
return (1/6) * Math.PI * diameter * diameter * diameter;
}
// ES6
const volumeOfSphere = diameter =>
(1/6) * Math.PI * diameter * diameter * diameter;
Or, you can use return but you must use the curly braces, like so:
const volumeOfSphere = diameter =>
{ return (1/6) * Math.PI * diameter * diameter * diameter };
But essentially, to make your code as neat and concise as possible, you can simplify everything by not using return nor curly braces.
2 Likes
Thank you so much. Made it very clear
1 Like
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.