Software Design
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreSoftware Design

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 22nd, 2003, 12:50 AM
UCFgirl UCFgirl is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2003
Posts: 2 UCFgirl User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Please Help-School Assignment

Hello, I have an assignment for school and I cannot figure out how to do it right. I am converting an algorithm into javascript. I am supposed to have a list of numbers, but I can only figure out how to do 1 number. This is my assignment, and below that is the code I have written. PLEASE HELP!!

Assignment:
Convert the following algorithm into JavaScript code within your HTML document. Your final web page should display the algorithm title, the input and the output.

Input:
Integerlist[10];

OTHER VARIABLES:
Integer sum;
Integer i;

INITIALIZATION:
FOR i = 0 to 9 DO
list[i] = random integer between 0 and 100;
ENDIF
sum = 0;

COMPUTATION:
FOR i = 0 to 9 DO
sum = sum + list[i];
ENDDO

OUTPUT:
return(sum);


And the code i wrote is:

<html>
<head>
<title>Sum()
</title>
</head>
<body>
<h1>Sum()</h1> <br><br>

<script language="JavaScript">

var list;
var sum;
var i;

i= [1, 2, 3, 4, 5, 6, 7, 8, 9]

list = Math.round(100 * Math.random())

for (i = 0; i < 10; i++)
{
list = Math.round(100 * Math.random())
}
sum = 0

for (i = 0; i < 10; i++)
{
sum = sum + list
}

document.write("the list is=" + list + "<br />")
document.write("the sum is=" + sum)





</script>
</body>
</html>

what am I doing wrong?
Thanks SO much!!!

Reply With Quote
  #2  
Old May 22nd, 2003, 08:29 AM
epl epl is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Location: Dublin
Posts: 413 epl User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 18 m 18 sec
Reputation Power: 13
try this:
Code:
  var list=new Array(10);// not sure about initialising this like this... maybe be unecessary or wrong
  var sum=0;
  var i;

  //generate list[] inputs
  for (i=0; i<10; i++)
   {list[i]=Math.round(100 * Math.random());}

  //iterate over list[], building up the running total
  for (i = 0; i < 10; i++)
   {sum+=list[i];}

  //output
  document.write("the list is: [");
  for (i = 0; i < 10; i++)
   {document.write(list[i]);
     if (i<9) {document.write(", ");}
   }
  document.write("]<br>the sum is: " + sum)

Last edited by epl : May 22nd, 2003 at 08:31 AM.

Reply With Quote
  #3  
Old May 22nd, 2003, 09:24 AM
Onslaught's Avatar
Onslaught Onslaught is offline
/(bb|[^b]{2})/
Dev Shed God (5000 - 5499 posts)
 
Join Date: Nov 2001
Location: Somewhere in the great unknown
Posts: 5,163 Onslaught User rank is Major General (70000 - 90000 Reputation Level)Onslaught User rank is Major General (70000 - 90000 Reputation Level)Onslaught User rank is Major General (70000 - 90000 Reputation Level)Onslaught User rank is Major General (70000 - 90000 Reputation Level)Onslaught User rank is Major General (70000 - 90000 Reputation Level)Onslaught User rank is Major General (70000 - 90000 Reputation Level)Onslaught User rank is Major General (70000 - 90000 Reputation Level)Onslaught User rank is Major General (70000 - 90000 Reputation Level)Onslaught User rank is Major General (70000 - 90000 Reputation Level)Onslaught User rank is Major General (70000 - 90000 Reputation Level)Onslaught User rank is Major General (70000 - 90000 Reputation Level)Onslaught User rank is Major General (70000 - 90000 Reputation Level)Onslaught User rank is Major General (70000 - 90000 Reputation Level)Onslaught User rank is Major General (70000 - 90000 Reputation Level) 
Time spent in forums: 6 Days 1 h 34 m 20 sec
Reputation Power: 791
In the future please consider a better subject title.
See this thread for more info.

Reply With Quote
  #4  
Old May 22nd, 2003, 03:42 PM
UCFgirl UCFgirl is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2003
Posts: 2 UCFgirl User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hey thanks, I got it figured out!!! Big Help!!!
-Melissa

Reply With Quote
  #5  
Old May 22nd, 2003, 05:38 PM
md_doc
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Quote:
Originally posted by UCFgirl
Hey thanks, I got it figured out!!! Big Help!!!
-Melissa


I cannot help but wonder if that means you helped her figure it out or the cut and paste of your code into her editor of choice worked

Reply With Quote
  #6  
Old May 22nd, 2003, 05:53 PM
epl epl is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Location: Dublin
Posts: 413 epl User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 18 m 18 sec
Reputation Power: 13
funny alright - i was a bit taken aback alright when i read it

well done figuring it out melissa - i suppose, to your credit, i did begin with a copy and paste of your code in the first place

good luck with your assignment (make sure to pass this link around to the rest of your class)

Last edited by epl : May 22nd, 2003 at 05:57 PM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreSoftware Design > Please Help-School Assignment

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap