Average of two numbers
DiggBlinkRedditDeliciousTechnorati
question by Jackson | Hard
The following program is intended to find the average of two numbers. The user will entertwo numbers(say 5 and 7) and the programm will write the answer to the screen(in this case 6).
However the current version, given below contains several errors. Your task will be to identify them, expain what is wrong, and say what the correct code should be
<SCRIPT LANGUAGE="Javascript">
// To find the average of two numbers
Var 1stValue, 2ndValue, answer;
1stValue = window.prompt('Enter number 1', ' ');
1stValue = parseFloat(1stValue);
2ndValue = window .prompt('Enter number 2', ' ');
2ndValue = ParseFloat(2ndValue);
Result = 1stValue+2ndValue /2;
document.write 'The average of' 1stValue and 2ndValue 'is' answer);
</SCRIPT>
a) Identify the errors on the above and rewrite the program and also find this code in the file average.html
b)For each distinct error that you identified, write down a short explanation of what you changed and why you made the change.
Post reply
Subscriptions
Re: Average of two numbersreply by Srirangan We can't keep doing your homework dude. At least make an attempt to answer the question yourself.
- Sri
Post reply
Subscriptions
Re: Average of two numbersreply by Jackson This is not a homework, Am doing a small Js research project at my work. I just need to make sure that what I do is correct from the expert's contributions.
I would apreciate your contribution this project will end 2 Jan 07 only one more question to come on this forum then you will see me answering many questions to help others.
Many thanks
Jackson
Post reply
Subscriptions
Re: Average of two numbersreply by Chris Hey, you out of luck mate, the question you are asking are for the second TMA in the Open Univeristy course M150 Data, Computing and Information. Well done for those who have declined the answer.
I know because I'm doing the course. I was looking for help but have managed to rewrite the correct program.
Have a go, if you read you course manual its all in there, you just being lazy.
Chris
Post reply
Subscriptions
Got a Javascript Question?
Just Sign Up and ask the top Javascript experts!
|