fjardis86

10-20-2008, 08:13 PM

I'm taking a beginning class at my school for Javascript. My teacher refuses to answer e-mails so I cannot get in touch with him to fix my problem. My assignment was to prompt a user to enter 5 integers, and then have a browser display the largest of the 5 integers. I was then asked to prompt the user to enter 1 more integer and if it was equal to one of the 5 other integers, display a statement respectively.

What happens with my script is once the user puts in the integers, the browser displays every integer, and also both statements (this integer is NOT equal/equal to the other integers.) I'm sure its a very simple problem, but I am a complete noob with coding, so I don't know what to do to just have the browser display the LARGEST integer, not every integer, as well as display ONE statement, not both.

Here is the code:

</html>

</body>

<script language="JavaScript" type="text/javascript">

var firstnumber = Number(prompt("Enter the first number"));

var secondnumber = Number(prompt("Enter the second number"));

var thirdnumber = Number(prompt("Enter the third number"));

var fourthnumber = Number(prompt("Enter the fourth number"));

var fifthnumber = Number(prompt("Enter the fifth number"));

if ( (firstnumber > secondnumber) && (firstnumber > thirdnumber) && (firstnumber > fourthnumber) && (firstnumber > fifthnumber) );

{

document.write(firstnumber);

}

if ( (secondnumber > firstnumber) && (secondnumber > thirdnumber) && (secondnumber > fourthnumber) && (secondnumber > fifthnumber) );

{

document.write(secondnumber);

}

if ( (thirdnumber > firstnumber) && (thirdnumber > secondnumber) && (thirdnumber > fourthnumber) && (thirdnumber > fifthnumber) );

{

document.write(thirdnumber);

}

if ( (fourthnumber > firstnumber) && (fourthnumber > secondnumber) && (fourthnumber > thirdnumber) && (fourthnumber > fifthnumber) );

{

document.write(fourthnumber);

}

if ( (fifthnumber > firstnumber) && (fifthnumber > secondnumber) && (fifthnumber > thirdnumber) && (fifthnumber > fourthnumber) );

{

document.write(fifthnumber);

}

var lastnumber = Number(prompt("Enter one last number"));

if ( (lastnumber == firstnumber) || (lastnumber == secondnumber) || (lastnumber == thirdnumber) || (lastnumber == fourthnumber) || (lastnumber == fifthnumber) );

{

document.write("The last number is equal to one of the other integers.");

}

if ( !(lastnumber == firstnumber) || (lastnumber == secondnumber) || (lastnumber == thirdnumber) || (lastnumber == fourthnumber) || (lastnumber == fifthnumber) );

{

document.write("The last number is NOT equal to one of the other integers.");

}

</script>

</body>

</html>

Here is a link to the site:

file:///C:/Documents%20and%20Settings/Fred/Desktop/JS_HW2.htm

I apologize if I'm breaking any rules on the board. The class is in about 2 hours, so I'm just hoping I can get a quick answer from anyway that can even read my code.

What happens with my script is once the user puts in the integers, the browser displays every integer, and also both statements (this integer is NOT equal/equal to the other integers.) I'm sure its a very simple problem, but I am a complete noob with coding, so I don't know what to do to just have the browser display the LARGEST integer, not every integer, as well as display ONE statement, not both.

Here is the code:

</html>

</body>

<script language="JavaScript" type="text/javascript">

var firstnumber = Number(prompt("Enter the first number"));

var secondnumber = Number(prompt("Enter the second number"));

var thirdnumber = Number(prompt("Enter the third number"));

var fourthnumber = Number(prompt("Enter the fourth number"));

var fifthnumber = Number(prompt("Enter the fifth number"));

if ( (firstnumber > secondnumber) && (firstnumber > thirdnumber) && (firstnumber > fourthnumber) && (firstnumber > fifthnumber) );

{

document.write(firstnumber);

}

if ( (secondnumber > firstnumber) && (secondnumber > thirdnumber) && (secondnumber > fourthnumber) && (secondnumber > fifthnumber) );

{

document.write(secondnumber);

}

if ( (thirdnumber > firstnumber) && (thirdnumber > secondnumber) && (thirdnumber > fourthnumber) && (thirdnumber > fifthnumber) );

{

document.write(thirdnumber);

}

if ( (fourthnumber > firstnumber) && (fourthnumber > secondnumber) && (fourthnumber > thirdnumber) && (fourthnumber > fifthnumber) );

{

document.write(fourthnumber);

}

if ( (fifthnumber > firstnumber) && (fifthnumber > secondnumber) && (fifthnumber > thirdnumber) && (fifthnumber > fourthnumber) );

{

document.write(fifthnumber);

}

var lastnumber = Number(prompt("Enter one last number"));

if ( (lastnumber == firstnumber) || (lastnumber == secondnumber) || (lastnumber == thirdnumber) || (lastnumber == fourthnumber) || (lastnumber == fifthnumber) );

{

document.write("The last number is equal to one of the other integers.");

}

if ( !(lastnumber == firstnumber) || (lastnumber == secondnumber) || (lastnumber == thirdnumber) || (lastnumber == fourthnumber) || (lastnumber == fifthnumber) );

{

document.write("The last number is NOT equal to one of the other integers.");

}

</script>

</body>

</html>

Here is a link to the site:

file:///C:/Documents%20and%20Settings/Fred/Desktop/JS_HW2.htm

I apologize if I'm breaking any rules on the board. The class is in about 2 hours, so I'm just hoping I can get a quick answer from anyway that can even read my code.