This is a discussion on "Help with some basic code" within the JavaScript Forum section. This forum, and the thread "Help with some basic code are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
Help with some basic code
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
|||
|
Help with some basic code
Hi
I'm new to both the forum and JavaScript and wondered if anyone could help me with some code I'm working on. The code involves two variables into which the user enters numbers (via window.prompt object/method). These numbers then require to be divided by 2 and the result stored in a third variable. Assuming we name the two entry variables value1 & value2 and the variable where the result needs to be stored result this is the code I've so far managed to produce: result = (value1 + value2 / 2); The problem is this doesn't compute correctly. Can anyone assist? netwarriorgizmo |
|
|
|
|||
|
Welcome to the forums!
Remember from Maths... Division is done before Addition, so value2 is being divided by two and then the result added to value1. You need to use brackets, like this: result = (value1 + value2)/2; |
|
|||
|
well, since Sirkent beat me to it, I'll just welcome you to the forumz
|
![]() |
| Tags |
| help, basic, code |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| code behind code doesnt work | skat | ASP.NET Forum | 4 | Feb 18th, 2008 10:05 |
| Very basic | MHHx | Starting Out | 6 | Nov 14th, 2007 06:50 |
| live search code and styleswitcher code | hebel | JavaScript Forum | 0 | May 12th, 2007 06:16 |
| Can somebody give me the code to hide the source code? | renren | JavaScript Forum | 7 | Mar 7th, 2006 12:27 |
| Basic ASP | xelrose99 | Classic ASP | 1 | Mar 9th, 2005 20:24 |