#### Archived

This topic is now archived and is closed to further replies.

# Need some help with javascript

This topic is 5925 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

It says syntax error on line 33


<!-- This application will find the circumference of a circle -->

<html>
<title> Circumference Solver </title>
<body>
<center>
This application will find the area of a cirlce given either the diameter of the radius <br />
pi = 3.14, not 22/7
</center>
<script language = "javascript">
// This application will find the circumference of a circle given the diameter or radius

var raddia = prompt("Do you know the radius or diamter of the circle?" , "");
var pi = 3.14;
var sUnits = prompt("What is the unit of measurement, ie ft, cm, in, m..." , "");
{
{
var radius1 = prompt("What is the radius of the cirlce?" , "");
var area1 = (dia*pi); /*This says area is diamter*pi*/
}
{
if (area1 > 0) /* If the area is greater than 0...*/
{
document.writeln(area1);
document.writeln(sUnits); /*This will write the area followed by the units*/
}
}
{
else
{
document.writeln("Invalid area, please imput another value" , ""); /* If area is < or = */
}
}
}
else /* THIS IS WHERE IT IS COMPLAINING */
{
{
var diameter = prompt("What is the diameter" , "");
var area2 = (diamter*pi); /* This will do virtually the same as the above*/
}
{
if (area2 > 0)
{
document.writeln(area2);
document.writeln(sUnits);
}
}
{
else
{
document.writeln("Invalid area, please imput another value" , "");
}
}
}
</script>
</html>

as you can see, the program is supposed to find the circumference in a circle and will prompt the use if he/she will imput the circumference or radius then calculating accordingly... Thank you very much!

##### Share on other sites
You seem to be separating your code into blocks unnecessarily.

{
var radius1 = prompt("What is the radius of the cirlce?" , "");
var area1 = (dia*pi); /*This says area is diamter*pi*/
}

You dont need a block around that. Equally so this could be the damaging part:

{
if (area1 > 0) /* If the area is greater than 0...*/
{
...
}
}
{
else
{
...
}
}

That is most likely screwing up your if/else statements because the if and else exist in two different blocks. You do this more than once too.

Another problem (unrelated):
var dia = (r+r);

You never defined r, but you meant to write radius1

The hackers must have gotten into the system through the hyperlink!!

1. 1
Rutin
27
2. 2
3. 3
4. 4
5. 5

• 11
• 9
• 9
• 9
• 14
• ### Forum Statistics

• Total Topics
633313
• Total Posts
3011318
• ### Who's Online (See full list)

There are no registered users currently online

×