Help with some basic code

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.



Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices


Closed Thread
 
LinkBack Thread Tools
  #1 (permalink)  
Old Jul 11th, 2004, 17:32
Junior Member
Join Date: Jul 2004
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
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??:

  #2 (permalink)  
Old Jul 11th, 2004, 18:29
Most Reputable Member
Join Date: Jul 2003
Posts: 1,856
Thanks: 0
Thanked 0 Times in 0 Posts
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;
  #3 (permalink)  
Old Jul 11th, 2004, 18:41
Highly Reputable Member
Join Date: Aug 2003
Location: Australia
Posts: 662
Thanks: 0
Thanked 0 Times in 0 Posts
well, since Sirkent beat me to it, I'll just welcome you to the forumz . We are glad to have you.
  #4 (permalink)  
Old Jul 11th, 2004, 18:59
Junior Member
Join Date: Jul 2004
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks guys, perfect!
Closed Thread

Tags
help, basic, code

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

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


All times are GMT. The time now is 10:33.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43