I am trying to get a result that looks like this
"The volume of the cone 261.66 is greater than the volume of the cylinder 785: false."
console.log("The volume of the cone " (10 / 3 * (3.14 * (5 **2))) "is greater than the volume of the cylinder " (10 * (3.14 * (5 **2)))): 261 > 785);
EDIT: Thanks for all your help everyone. I can believe I didn't see that I didn't put and thanks for point out ":" I was so tired and I just wanted to finish I can't believe I wasted all that time getting the math to work just to miss a and forgot about :
You missed a and ":"
With template literals
console.log(`The volume of the cone ${(10 / 3 * (3.14 * (5 **2)))} is greater than the volume of the cylinder ${(10 * (3.14 * (5 **2)))} : ${261 > 785}`);
CodePudding user response:
It should be one from below
String Concatenation
console.log("The volume of the cone " (10 / 3 * (3.14 * (5 **2))) "is greater than the volume of the cylinder " (10 * (3.14 * (5 **2))) ":" (261 > 785));
Please Note the importance of the paranthesis in (261 > 785)
. Removing the bracket will throw a false
as output. Because the string expression in console will be checked against > 785
if the bracket is removed, that will result in false
as result
OR
Template Literals
console.log(`The volume of the cone ${(10 / 3 * (3.14 * (5 **2)))} is greater than the volume of the cylinder ${(10 * (3.14 * (5 **2)))} : ${261 > 785}`);
CodePudding user response:
You missed adding
or concatenation after the numerical expressions and :
should have been in quotes too as its a string. Better yet use templating, both examples below:
// With concatination
console.log("The volume of the cone " (10 / 3 * (3.14 * (5 ** 2))) " is greater than the volume of the cylinder " (10 * (3.14 * (5 ** 2))) ": " (261 > 785));
// With templating
console.log(`The volume of the cone ${(10 / 3 * (3.14 * (5 ** 2)))} is greater than the volume of the cylinder ${(10 * (3.14 * (5 ** 2)))}: ${(261 > 785)}`);