/    Sign up×
Community /Pin to ProfileBookmark

Need some serious help here…

I’m trying to get this assignment done for a Javascript class that I’ve been working on for almost 2 weeks now. Basically the script has to take inputs on 3 sides of a triangle and tell you if they are valid or not using the 3/4/5 rule. If it turns out to be a right triangle it has to pop up an alert box to tell you that as well. The script keeps taking inputs until you quit. Here’s what I have so far, I’d appreciate it if someone could steer me in the right direction:

[code]
<html>
<head>
<title> Programming Assignment 2 </title>
<body>
<h1> Programming Assignment 2 – Triangle Calculator </h1>

<h3>Please input the lengths of the 3 sides of the triangle in the boxes below.</h3>

<form name=”Triangle”>
Side 1: <input type=”text” name=”sidea” value=””><br/>
Side 2: <input type=”text” name=”sideb” value=””><br/>
Side 3: <input type=”text” name=”sidec” value=””><br/>
<input type=”reset” name=”reset1″ value=”Clear”>
<input type=”submit” name=”submit1″ value=”Submit”>
</form>

<script type=”text/javascript”>

document.forms[“Triangle”]

val1 = parseInt(sidea);
val2 = parseInt(sideb);
val3 = parseInt(sidec);

function right(){
if ((Math.pow(val1,1/2)) + (Math.pow(val2,1/2)) == Math.pow(val3,1/2))
if ((Math.pow(val2,1/2)) + (Math.pow(val3,1/2)) == Math.pow(val1,1/2))
if ((Math.pow(val1,1/2)) + (Math.pow(val3,1/2)) == Math.pow(val2,1/2)){
alert(“This is a right triangle.”);
}
}

function validate(){
if (val1 + val2 > val3 || val1 + val3 > val2 || val2 + val3 > 1){
alert(“This is a valid triangle.”);
}
else{
alert(“This is not a valid triangle.”)
}
}

</script>

<noscript>
<h2>JavaScript is disabled. To see what this assignment does please enable it in your browser.</h2>
</noscript>

</body>
</html>
[/code]

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@ZeroKilledMar 04.2008 — i had not looked your code, but i'm pretty sure this is a similar thread to http://www.webdeveloper.com/forum/showthread.php?t=174861&highlight=triangle
Copy linkTweet thisAlerts:
@Arty_EffemMar 04.2008 — I'd appreciate it if someone could steer me in the right direction[/QUOTE]Take this direction. FireFox -> Tools -> Error Console

Also you should not submit the form, so don't use a submit-type button.

Use:
[CODE]<input type='button onclick="validate" value="Check">[/CODE]
Copy linkTweet thisAlerts:
@KorMar 04.2008 — Take this direction. FireFox -> Tools -> Error Console

Also you should not submit the form, so don't use a submit-type button.

Use:
[CODE]<input type=[COLOR="Red"]"[/COLOR]button[COLOR="Red"]"[/COLOR] onclick="validate[COLOR="Red"]()[/COLOR]" value="Check">[/CODE][/QUOTE]


You mistyped, in hurry, the quotes and the function's arguments block...?
×

Success!

Help @SportyPaul74 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...