THE ZEPINT NETWORK

programmer assist

Javascript Javascript XML Feeds

Javascript Questions Javascript Solutions Javascript Articles

JavaScript, in its more modern form, is an object-based scripting programming language based on the concept of prototypes. The language is best known for its use in websites, but is also used to enable scripting access to objects embedded in other applications. It was originally developed by Brendan Eich of Netscape Communications Corporation under the name Mocha, then LiveScript, and finally renamed to JavaScript.

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 numbers

reply 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 numbers

reply 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 numbers

reply 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!

Search via Google

User Login

Email Address

Password

Javascript Experts

Rank Expert Points
#1 Bejaan 500
#2 Srirangan 150
This a list of the Top Javascript experts, how many points do you have?

Leading Experts

Rank Expert Points
#1 frankzzsword 4600
#2 Bejaan 2900
#3 csfreak 1100
#4 Anurag 700
#5 keyvez 700
#6 nnarasimha 600
#7 Nakata 600
#8 martinig 600
#9 mastercomputers 400
#10 Huntress 150
#11 Adkron 150
#12 Yogesh 100
#13 lexxwern 100
#14 Mustan Khan 100
#15 poizn 100
This is a list of overall best performing experts, how many points do you have?