Question:
Problem with making Arrays in Javascript.?
paintballer100
2007-11-07 11:26:08 UTC
So i have to make this program to help us understand Arrays, but i missed a few days, and im a little behind... I was wondering if anyone could help me out with it? The instructions are-

Write a program that will take in all the elements of 2 3x3 matrices and give the user the following menus options. Yout will recieve points for functionality and comments and design of your code.
1. Enter matrix A
2. Enter matrix B
3. Add the matrices
4. Subtract the matrices
5. Multiply the matrices
6. Quit
Wow points for computing the determinant of the matrix.


Any help is GREATLY appreciated!
Three answers:
richarduie
2007-11-08 20:42:37 UTC














Menu:







































input first array
input second array
add arrays
subtract arrays
multiply arrays (inner product)
quit










Array Input:






























 


 


 




Jon VS
2007-11-07 11:54:57 UTC
Well, without getting into too much detail, a matrix is a two-dimensional array; this means you have one "parent" array, and each element of that array is its own array.



// parent array

var matrix = new Array(3);



// each element of the parent array is its own array

matrix[0] = new Array(3);

matrix[1] = new Array(3);

matrix[2] = new Array(3);



You could use JavaScript to show and hide a 3x3 table of input fields whose values could be accepted through form input (it'd be best to make sure your form doesn't actually submit, since that would involve page refreshes). Make sure you check the fields for valid input (numbers only) before you accept them.



Then, when a button is clicked, I'd use for loops to iterate through both dimensions of both matrices and use those values to add, subtract, and multiply those values.



I'm not sure what is meant by "Quit"; maybe that means your matrices are cleared so that new values may be entered. Are you sure you don't mean that you are programming in Java? This answer would be similar in Java, though the syntax would be different. If so, you would either have to accept input through the Console (using a Scanner) or, if you're using a GUI, through a form control (JTextField in a JFrame, TextField in an AWT frame).
stephene
2007-11-07 11:48:35 UTC
Could you clarify if this question is indeed regarding "Javascript", or whether you really meant "Java"



It makes a big difference.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...