Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialTadjiev Codes
9,626 Pointsnet::ERR_ABORTED 404 Untitled-1.js:43 Uncaught SyntaxError: Unexpected identifier what's the error in console?
GET http://127.0.0.1:58597/css/styles.css net::ERR_ABORTED 404 (Not Found) Untitled-1.js:43 Uncaught SyntaxError: Unexpected identifier
// 2. Create a function that calculates the area of a rectangle. // The function should accept the width and height as arguments // and return the area of that rectangle. // The area of a rectangle is the width * height function getArea (width, height) { return width * height; }
// 3. Create a function that calculates the volume of a rectangular prism. // The function should accept the width, height and length as arguments // and return the volume of that rectangular prism. // The volume of a rectangular prism is the width * height * length function calculateArea ( width, height, length) { var area = width * height * length; return area; }
// 4. Create a function that calculates the area of a circle. // The function should accept the radius of the circle as an argument // and return the area of that circle. // The area of a circle is the value of π * radius^2
function areaCircle (radius){
return Math.PI * Math.pow(radius,2) ;
}
// 5. Create a function that calculates the volume of a sphere. // The function should accept the radius of the sphere as an argument // and return the volume. // The volume of a circle is: 4/3 * π * radius^3
function volSphere (radius) { return (4/3) Math.PI * Math.pow(radius,3) ; }
// 6. Use console.log to test each function and output to the JavaScript console // Here are the values to test and the expected results // -- Area of rectangle that is 5 wide and 22 tall: 110 // -- Volume of a rectangular prism that is 4.5 x 12.5 x 17.4: 978.7499999999999 // -- Area of a circle that with a radius of 7.2: 162.8601631620949 // -- Volume of a spehere with a radius of 7.2: 1563.4575663561109
console.log (getArea (5,22) ); console.log (calculateArea (4.5, 12.4, 17.4,) ); console.log ( areaCircle (7.2) ); console.log ( volSphere (7.2) );
3 Answers
Henrik Christensen
Python Web Development Techdegree Student 38,322 Pointsconsole.log (calculateArea (4.5, 12.4, 17.4,)); // the comma after 17.4 would cause a syntax error (might be the problem)
KRIS NIKOLAISEN
54,971 PointsYour formula for the volume of a sphere is missing a multiplication sign
{ return (4/3) Math.PI * Math.pow(radius,3) ; }
should be
{ return (4/3)* Math.PI * Math.pow(radius,3) ; }
Tadjiev Codes
9,626 PointsThanks for the response. But i still don't understand why there's no output on console.log and just undefined Syntax Error(( <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Practice JavaScript Math</title> <link href="css/styles.css" rel="stylesheet">
</head>
<body>
<script src="Untitled-1.js"></script>
</body>
</html>
// Even the html is connected in the right way as i guess
Armando Rosario
959 Pointsim getting this same error too. Cant find the problem
Tadjiev Codes
9,626 PointsTadjiev Codes
9,626 PointsThanks a lot) THat was such a small thing that I couldn't notice even. So means at the end of () you shouldn't be using any signs such as a comma or semicolon...