| | |
Lost by tried and tried
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Apr 2008
Posts: 12
Reputation:
Solved Threads: 0
Please help the question appears below and my so-called attempt appears after that as you can see I am relatively new to java, I only manage to do the sum part.
Write a script that takes three integers from the user and displays the sum. average, product, smallest and largest of the numbers in an alert dialog.
When I run the above noting happens, the screen is absolutely blank and there’s no errors. This is for an assignment.
Write a script that takes three integers from the user and displays the sum. average, product, smallest and largest of the numbers in an alert dialog.
html Syntax (Toggle Plain Text)
<script type="text/javajscript"> <!-- var firstNumber, secondNumber, number 1, number2, number3, sum; firstNumber= window.prompt( 'Enter the first number", "0" ); secondNumber = window.prompt( 'Enter the second number", '0' ); ThirdNumber = window.prompt( 'Enter the third number", '0' ); number1 = parselnt( firstNumber ); number2 = parselnt( secondNumber );number3 = parselnt( ThirdNumber ); sum = number1 + number2 +number3; window.status =( sum: " + sum + "); <-- </script> </head> <body onload="window.prompt;"> </body> </html>
When I run the above noting happens, the screen is absolutely blank and there’s no errors. This is for an assignment.
Last edited by peter_budo; Jul 22nd, 2008 at 3:32 pm. Reason: Keep It Organized - please use [code] tags
Java != JavaScript. They have similar names (purposefully done so by the JavaScript creators), and a somewhat similar syntax (again, purposefully done), but that's all. Next time post to a JavaScript forum. I have already requested that the admins move this one, so don't bother creating a new one there.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
•
•
•
•
Please help the question appears below and my so-called attempt appears after that as you can see I am relatively new to java, I only manage to do the sum part.
Write a script that takes three integers from the user and displays the sum. average, product, smallest and largest of the numbers in an alert dialog.
<script type="text/javajscript">
<!--
/*
var firstNumber,
secondNumber, //this, and the following will produce errors
number 1,
number2,
number3,
sum;
*/
//you should declare your vars in one line when grouping:
var firstNumber, secondNumber, number 1, number2, number3, sum;
firstNumber= window.prompt( 'Enter the first number", "0" );
secondNumber = window.prompt( 'Enter the second number", '0' );
ThirdNumber = window.prompt( 'Enter the third number", '0' );
number1 = parselnt( firstNumber ); number2 = parselnt( secondNumber );number3 = parselnt( ThirdNumber );
sum = number1 + number2 +number3;
/*
window.status =( sum: " + sum + "); //this is where your code should fail completely!
*/
window.status = "sum: " + sum;
/*<--*/
-->
</script>
</head>
<body onload="window.prompt;">
</body>
</html>
When I run the above noting happens, the screen is absolutely blank and there’s no errors. This is for an assignment.
•
•
Join Date: Apr 2008
Posts: 12
Reputation:
Solved Threads: 0
•
•
•
•
Your question is JavaScript related all right, but your code contains some errors. Whatch for portions marked in red.
I’ve made the recommended changes but the problem still persists as it doesn’t prompt the user for the integer an I have no idea how to displays the average, product, smallest and largest of the numbers in an alert dialog. All I manage was the sum part.
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<script type="text/javajscript"> <!-- var firstNumber, secondNumber, number 1, number2, number3, sum; firstNumber= window.prompt( 'Enter the first number", "0" ); secondNumber = window.prompt( 'Enter the second number", '0' ); ThirdNumber = window.prompt( 'Enter the third number", '0' ); number1 = parselnt( firstNumber ); number2 = parselnt( secondNumber );number3 = parselnt( ThirdNumber ); sum = number1 + number2 +number3; window.status = "sum: " + sum; --> </script> </head> <body onload="window.prompt;"> </body> </html>
Last edited by Tekmaven; Jul 24th, 2008 at 3:14 am. Reason: Code tags
•
•
•
•
Thanks Troy III, for taking the time out to look at my script.
I’ve made the recommended changes but the problem still persists as it doesn’t prompt the user for the integer an I have no idea how to displays the average, product, smallest and largest of the numbers in an alert dialog. All I manage was the sum part.
<script type="text/javajscript">
<!--
var firstNumber, secondNumber, number 1, number2, number3, sum;
firstNumber= window.prompt( 'Enter the first number", "0" );
secondNumber = window.prompt( 'Enter the second number", '0' );
ThirdNumber = window.prompt( 'Enter the third number", '0' );
number1 = parselnt( firstNumber ); number2 = parselnt( secondNumber );number3 = parselnt( ThirdNumber );
sum = number1 + number2 +number3;
window.status = "sum: " + sum;
-->
</script>
</head>
<body onload="window.prompt;">
</body>
</html>
1. script type="text/javascript". You have a typo.
2. its parseInt and not parselnt.
3.
•
•
•
•
<body onload="window.prompt;">
And ofcourse, don't forget points mentioned by Troy III !
Ignorance is definitely not bliss!
*PM asking for help will be ignored*
*PM asking for help will be ignored*
As a matter of a fact - your code will give you absolutely NOTHING!
Let me first explain you few things,
-now that you've learned that Java and JavaScript are two completely different languages, there is no single line in your code where you didn't put at least one [?deliberate!] error.
vars can be declared either separately:
or grouped with one keyword in a comma-separated list:
This will produce another error:
there is no comma between "tw" & "o", or there is an illegal whitespace in the name of var.
(your
You've commented your script
You have deliberately missmathched quotes
You've managed to switch "I" with "L" in every
Finishing with your special mess:
using undefined
Not to forget your prime error
To round it up, your
That's because you didn't write anything of that kind in your (provided) code!
Let me first explain you few things,
-now that you've learned that Java and JavaScript are two completely different languages, there is no single line in your code where you didn't put at least one [?deliberate!] error.
vars can be declared either separately:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
var one; var two; var three;
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
var one, two, three;
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
var one, tw o, three;
there is no comma between "tw" & "o", or there is an illegal whitespace in the name of var.
(your
number 1 error reproduced).You've commented your script
<!-- ... <-- , this can never happen to be one of a "new to Java" error. You have deliberately missmathched quotes
window.prompt( 'Enter the first number", "0" ); in every single line required.You've managed to switch "I" with "L" in every
parselnt( firstNumber ); function counting on similar visual representation of I and smallcaps L in fonts currently used.Finishing with your special mess:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
window.status =( sum: " + sum + ");
sum: but converting the existing "sum" var into a string literal with no meaning at all.Not to forget your prime error
<script type="text/javajscript"> requiring the browser to use an unknown and inexistent scripting language to interpret your javascript. The most fundamental of all errors previously mentioned.To round it up, your
<body onload="window.prompt;"> is absolute nonesense.That's because you didn't write anything of that kind in your (provided) code!
•
•
Join Date: Apr 2008
Posts: 12
Reputation:
Solved Threads: 0
•
•
•
•
As a matter of a fact - your code will give you absolutely NOTHING!
Let me first explain you few things,
-now that you've learned that Java and JavaScript are two completely different languages, there is no single line in your code where you didn't put at least one [?deliberate!] error.
vars can be declared either separately:
or grouped with one keyword in a comma-separated list:JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
var one; var two; var three;
This will produce another error:JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
var one, two, three;
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
var one, tw o, three;
there is no comma between "tw" & "o", or there is an illegal whitespace in the name of var.
(yournumber 1error reproduced).
You've commented your script<!-- ... <--, this can never happen to be one of a "new to Java" error.
You have deliberately missmathched quotes
window.prompt( 'Enter the first number", "0" );in every single line required.
You've managed to switch "I" with "L" in everyparselnt( firstNumber );function counting on similar visual representation of I and smallcaps L in fonts currently used.
Finishing with your special mess:
using undefinedJavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
window.status =( sum: " + sum + ");sum:but converting the existing "sum" var into a string literal with no meaning at all.
Not to forget your prime error<script type="text/javajscript">requiring the browser to use an unknown and inexistent scripting language to interpret your javascript. The most fundamental of all errors previously mentioned.
To round it up, your<body onload="window.prompt;">is absolute nonesense.
That's because you didn't write anything of that kind in your (provided) code!
<script LANGUAGE="JAVASCRIPT">
var firstnumber = prompt("Enter first number and Click OK", "0");
var secondnumber = prompt("Enter second number and Click Ok", "0);
var thirdnumber = prompt("Enter third number and Click Ok", "0);
var total = Math.floor(firstnumber)+ Math.floor(secondnumber)+ Math.floor(thirdnumber);
alert("The Sum is: " + total ) // this line give me the correct sum! But I need average, product, smallest and largest of the numbers as well.
alert("The Sum is: " + total + " Average: " + average + " product: " + product +" largest " + largest + " smallest " + smallest) //when I try to replace the above line with this one I get errors.
function YourCost1(){
if(firstnumber > secondnumber && firstnumber > thirdnumber){
var largest= firstnumber;
}
else if(secondnumber > firstnumber && secondnumber > thirdnumber){
var largest= secondnumber;
}
else if(thirdnumber > firstnumber && thirdnumber > secondnumber){
var largest= thirdnumber;
}
if(firstnumber < secondnumber && firstnumber < thirdnumber){
var smallest= firstnumber;
}
else if(secondnumber < firstnumber && secondnumber < thirdnumber){
var smallest= secondnumber;
}
else if(thirdnumber < firstnumber && thirdnumber < secondnumber){
var smallest= thirdnumber;
}
}
</SCRIPT>
"average" has to do with, do it yourself math: ( a + b + c ) / 3, as in primary school.
sunny, you are again deliberately messing with quotes
("Enter second number and Click Ok", "0
you don't need it especially if you haven't writen O instead of 0!
your elseif
is one hell of a junk, there is only one elseif in both real life and in coding.
and there can't be the largest or the smallest "product" you mean "sum" of 1+2+3; -what on earth were you thinikng? the smallest and the largest is always the exact same value of 6,
etc etc ...
sunny, you are again deliberately messing with quotes
("Enter second number and Click Ok", "0
you don't need it especially if you haven't writen O instead of 0!
your elseif
is one hell of a junk, there is only one elseif in both real life and in coding.
and there can't be the largest or the smallest "product" you mean "sum" of 1+2+3; -what on earth were you thinikng? the smallest and the largest is always the exact same value of 6,
etc etc ...
•
•
Join Date: Apr 2008
Posts: 12
Reputation:
Solved Threads: 0
•
•
•
•
"average" has to do with, do it yourself math: ( a + b + c ) / 3, as in primary school.
sunny, you are again deliberately messing with quotes
("Enter second number and Click Ok", "0
you don't need it especially if you haven't writen O instead of 0!
your elseif
is one hell of a junk, there is only one elseif in both real life and in coding.
and there can't be the largest or the smallest "product" you mean "sum" of 1+2+3; -what on earth were you thinikng? the smallest and the largest is always the exact same value of 6,
etc etc ...
Ok I sort of worked it out. I still don’t know how to do the Product bit, Largest and Smallest. O and one more problem I cannot seem to get the sum and average onto the same alert box. I had to add two “alert” to check if the math is correct.
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<script LANGUAGE="JAVASCRIPT"> var firstnumber = prompt("Enter first number and Click OK", "0"); var secondnumber = prompt("Enter second number and Click Ok", "0"); var thirdnumber = prompt("Enter third number and Click Ok", "0"); var total = Math.floor(firstnumber)+ Math.floor(secondnumber)+ Math.floor(thirdnumber); var average= (Math.floor(firstnumber)+ Math.floor(secondnumber)+ Math.floor(thirdnumber))/3; alert("The Sum is:" + total); alert("average: "+average) function YourCost1(){ if(firstnumber > secondnumber && firstnumber > thirdnumber){ var largest= firstnumber; } else if(thirdnumber > firstnumber && thirdnumber > secondnumber){ var largest= thirdnumber; } if(firstnumber < secondnumber && firstnumber < thirdnumber){ var smallest= firstnumber; } else if(secondnumber < firstnumber && secondnumber < thirdnumber){ var smallest= secondnumber; } } </SCRIPT>
Last edited by Tekmaven; Jul 24th, 2008 at 3:20 am. Reason: Code tags
OK
try:
try: to remove the junk you use for this simple task: meaning following: taht can't posibly be working!
try:
alert("The Sum is:" + total + "; The average is: " + average); , to alert them both in one turn.try:
var largest = Math.max(firstnumber, secondnumber, thirdnumber);
var smallest = Math.min(firstnumber, secondnumber, thirdnumber);
alert("smallest:" + smallest + "; largest: " + largest )if(firstnumber > secondnumber && firstnumber > thirdnumber){
var largest= firstnumber;
}
else if(thirdnumber > firstnumber && thirdnumber > secondnumber){
var largest= thirdnumber;
}
if(firstnumber < secondnumber && firstnumber < thirdnumber){
var smallest= firstnumber;
}
else if(secondnumber < firstnumber && secondnumber < thirdnumber){
var smallest= secondnumber; Last edited by Troy III; Jul 23rd, 2008 at 10:53 am.
![]() |
Similar Threads
- recover lost file in windows XP (Windows NT / 2000 / XP)
- Body Text lost when sending hotmail (Web Browsers)
- Quick Launch toolbar lost (Windows 95 / 98 / Me)
- Lost browser links,internet options etc...toolbar (Web Browsers)
- Have I lost RAM? (Motherboards, CPUs and RAM)
- lost address book addresses (OS X)
- IDE devices lost during post W2K (Windows NT / 2000 / XP)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: urgent help needed pls..............
- Next Thread: Is this Strange problem due to virus ?
| Thread Tools | Search this Thread |
ajax ajaxcode ajaxexample ajaxhelp ajaxjspservlets animate automatically beta box browser bug calendar captchaformproblem checkbox child class close column createrange() css cursor debugger dependent disablefirebug dom download dropdown editor element embed engine error events explorer ext file form forms getselection google gwt gxt hiddenvalue highlightedword hint html htmlform ie7 ie8 iframe images internet java javascript javascripthelp2020 jawascriptruntimeerror jquery jsf jsfile jump libcurl math media microsoft mimic object onmouseoutdivproblem onreadystatechange parent paypal pdf php player position post problem programming progressbar regex runtime scroll search security select session shopping size software sql text textarea unicode w3c web website window windowofwords windowsxp wysiwyg \n






