473,403 Members | 2,338 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

does this look right to people

/ / To find the average of two numbers var 1stNumber, 2ndNumber,
answer;
1stNumber = window. prompt( 'Enter number 1' , ' ') ;
1stNumber =parseFloat (1stNumber);
2ndNumber = window.prompt ( 'Enter number 2' , ' ') ;
2ndNumber = parseFloat (2ndNumber) ; answer = 1stNumber + 2ndNumber /
2; document.write
( 'The average of' 1stNumber and 2ndNumber ' is ' answer)
Jul 23 '05 #1
2 950
Lee
javadoc said:

/ / To find the average of two numbers var 1stNumber, 2ndNumber,
answer;
1stNumber = window. prompt( 'Enter number 1' , ' ') ;
1stNumber =parseFloat (1stNumber);
2ndNumber = window.prompt ( 'Enter number 2' , ' ') ;
2ndNumber = parseFloat (2ndNumber) ; answer = 1stNumber + 2ndNumber /
2; document.write
( 'The average of' 1stNumber and 2ndNumber ' is ' answer)


No.
Variable names shouldn't start with numbers.
Division has higher precedence than addition, so your expression
would produce the first number plus half of the second number.
You can use parentheses to force the addition to happen first.

Jul 23 '05 #2
javadoc wrote :
/ / To find the average of two numbers var 1stNumber, 2ndNumber,
answer;
1stNumber = window. prompt( 'Enter number 1' , ' ') ;
1stNumber =parseFloat (1stNumber);
2ndNumber = window.prompt ( 'Enter number 2' , ' ') ;
2ndNumber = parseFloat (2ndNumber) ; answer = 1stNumber + 2ndNumber /
2; document.write
( 'The average of' 1stNumber and 2ndNumber ' is ' answer)


There are a number of syntax errors in your code.
Here is a correct version:

FirstNumber=window.prompt('Enter number 1','')
FirstNumber=parseFloat(FirstNumber)
SecondNumber=window.prompt('Enter number 2','')
SecondNumber=parseFloat(SecondNumber)
answer=(FirstNumber+SecondNumber)/2
document.write('The average of '+FirstNumber+' and '+SecondNumber)
document.write(' is '+answer)

Bart
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: FAQPoster | last post by:
An HTML version of this document is available at: http://www.mvps.org/access/netiquette.htm Feeling left out? Alone? Wondering why everyone's ignoring you? Or why you're being flamed for what...
0
by: FAQPoster | last post by:
An HTML version of this document is available at: http://www.mvps.org/access/netiquette.htm Feeling left out? Alone? Wondering why everyone's ignoring you? Or why you're being flamed for what...
13
by: Jason Huang | last post by:
Hi, Would someone explain the following coding more detail for me? What's the ( ) for? CurrentText = (TextBox)e.Item.Cells.Controls; Thanks. Jason
14
by: Anoop | last post by:
Hi, I am new to this newsgroup and need help in the following questions. 1. I am workin' on a GUI application. Does C# provides Layout Managers the way Java does to design GUI? I know that it...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.