Jump to content
• Advertisement

#### 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.

If you intended to correct an error in the post then please contact us.

## Recommended Posts

It says syntax error on line 33


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

<html>
<head>
<title> Circumference Solver </title>
</head>
<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..." , "");
if (raddia == "radius")
{
{
var radius1 = prompt("What is the radius of the cirlce?" , "");
var dia = (r+r); /*This says diameter = radius1 + radius1*/
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>
</head>
</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 this post

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

{
var radius1 = prompt("What is the radius of the cirlce?" , "");
var dia = (r+r); /*This says diameter = radius1 + radius1*/
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!!

Invader''s Realm

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Contributors

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

• 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

×

## Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!