473,397 Members | 2,099 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,397 software developers and data experts.

basic math and arrays

This is this impossible question I have to do I dont even know how to start it.

2) The physics equation for Force, F = m*a. (3pt)
Means force (N) is equals to mass (kg) times by acceleration (m/s^2)
...Use an array to store 10 masses and another array to store 10 accelerations.
...Use a loop to calculate and output (document.write) the forces generated.
Sample output: 5(kg) * 10 (m/s^2) = 50 (N)


??????????????????????????????????????????
May 10 '07 #1
7 1663
iam_clint
1,208 Expert 1GB
thats not too hard ! come on i'll help you get started but because its a class I won't give you the full code. (tsdn policies);


so you make an array i would go about it like this

Expand|Select|Wrap|Line Numbers
  1. var masses = [1, 23, 43, 34, 51, 26, 57, 78, 89, 10];
  2. var mass = [masses];
  3.  
This is how an array is made

then to pull the data just use
Expand|Select|Wrap|Line Numbers
  1. mass[0][2] this would = 23
  2.  
todo some javascript math i use Math.floor()
Math.floor(Math functions here)


then you need a loop a loop would be made like this for example
Expand|Select|Wrap|Line Numbers
  1. for (i=0; i<10; i++) {
  2. dostuff
  3. }
  4.  

its i<10 because it starts at 0 so it would be 10 overall when it stops at 9.


document.write is used like this
Expand|Select|Wrap|Line Numbers
  1.  
  2. document.write("hello people!");
  3.  
to add vars to a document.write you do
Expand|Select|Wrap|Line Numbers
  1. document.write("hello people!"+mass[0][i]+" mass!");
  2.  
May 10 '07 #2
I need to do a physics equation using Javascript it needs to use the array variable and it needs to contain 10 different equations. I need a equation that looks something like this

5(kg) * 10 (m/s^2) = 50 (N)
May 16 '07 #3
iam_clint
1,208 Expert 1GB
did I not already answer this question for you in this Thread?
May 16 '07 #4
acoder
16,027 Expert Mod 8TB
did I not already answer this question for you in this Thread?
This calls for a merging. Threads merged.
May 17 '07 #5
acoder
16,027 Expert Mod 8TB
I need to do a physics equation using Javascript it needs to use the array variable and it needs to contain 10 different equations. I need a equation that looks something like this

5(kg) * 10 (m/s^2) = 50 (N)
You have been given enough information to attempt the problem yourself. If you don't know the basics of javascript, see the tutorial links in the Offsite Links thread at the top of this forum.

Make an attempt and if you get stuck on a particular part, then post again.
May 17 '07 #6
Thank you guys This is this code that i used and it worked

<script>

var nAcc = new Array();
nAcc[0] = 3;
nAcc[1] = 4;
nAcc[2] = 5;
nAcc[3] = 6;
nAcc[4] = 7;
nAcc[5] = 8;
nAcc[6] = 9;
nAcc[7] = 10;
nAcc[8] = 11;
nAcc[9] = 12;

var nMass = new Array();
nMass[0] = 3;
nMass[1] = 4;
nMass[2] = 5;
nMass[3] = 6;
nMass[4] = 7;
nMass[5] = 8;
nMass[6] = 9;
nMass[7] = 10;
nMass[8] = 11;
nMass[9] = 12;
var nForce=0;


for (n=0; n<10; n++){
nForce = nAcc[n] * nMass[n];
document.write(nForce + " (N)=" + nMass[n] +"(m/s^2) * " + nAcc[n]+ "kg<br>");

}

</script>
May 28 '07 #7
iam_clint
1,208 Expert 1GB
cool good for you.... i had written this code out before i told you how to do it... i made mine with a nested loop for all possibilities.
Expand|Select|Wrap|Line Numbers
  1. <script>
  2. function calcForce() {
  3.     var masses = [2, 4, 5, 12, 1232, 289, 925, 892, 102, 383];
  4.     var mass = [masses];
  5.     var accelerations = [20, 12, 44, 218, 12, 33, 11, 22, 23, 78];
  6.     var acceleration = [accelerations];
  7.     for (i=0; i<10; i++) {
  8.         for (b=0; b<10; b++) {
  9.             document.write(mass[0][i]+"(kg) * "+acceleration[0][b]+"(m/s^2) = "+Math.floor(mass[0][i]*acceleration[0][b])+" (N)<br>");
  10.         }
  11.     }
  12. }
  13. </script>
  14. <input type="button" onclick="calcForce()" value="Test">
  15.  
May 29 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: KellyH | last post by:
Hi, I hope someone can point me in the right direction. I'll get it out of the way: Yes, I am a college student. No, I am not looking for anyone to do my homework, just looking for help. I have...
41
by: Psykarrd | last post by:
I am trying to declare a string variable as an array of char's. the code looks like this. char name; then when i try to use the variable it dosn't work, however i am not sure you can use it...
10
by: John | last post by:
Hi all... Either I'm doing really something really stupid - or maybe there is some bug somewhere (optimizing?). In a function I have: int x1, y1, x2, y2; float dR, dX, dY; dR =...
56
by: Dave Vandervies | last post by:
I just fixed a bug that some of the correctness pedants around here may find useful as ammunition. The problem was that some code would, very occasionally, die with a segmentation violation...
4
by: Sheldon | last post by:
Hi, I have a written a script that will check to see if the divisor is zero before executing but python will not allow this: if statistic_array > 0.0: statistic_array =...
11
by: frankie_85 | last post by:
Hi everyone, I just made a simple code which is part of my assignment but I can't figure it out what's wrong with it. (always give me error messages) What the code basically does is: a...
9
by: Ken Fine | last post by:
Hi there, I have written a simple function that attempts to set the angle of objects so as to place them in aesthetically appealing ways. The code follows; there is some stupidness in it (e.g. a...
0
by: namit101 | last post by:
Hi, does c# provide any classes for handling single dimension vector math (i.e., something to adding two double arrays)? Does anyone know any good opensource math libraries that would accomplish...
11
by: moltendorf | last post by:
Hey everyone, as I have been by far pleased with some of the top helpers on this forum, I have decided to send another one your way. Even though I am personally having minimal issues with this...
4
by: T | last post by:
hi, Just wondering what tools are available for authoring in XML for docs that have complex math environments. Like equation arrays, multiline equations, etc. The kind of environments AMSLaTeX...
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
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.