need help with this

January 31, 2010 at 08:01:20
Specs: Windows Vista
var plantHeights = [15,16,17,18,19];
var plantNumbers = [2,1,6,4,2];
var product = new Array(5);

for (var count = 1; count <= productArray; count = count + 1)
product = plantHeights * plantNumbers;
document.write( product);
i cannot get the product to write out the plantHeights * plantNumbers and store them in a new array can anybody help

See More: need help with this

Report •

January 31, 2010 at 13:40:06
i've never worked with C++ before, but i'm wanting to learn it.
with that issue clarified, you might need curlies on the array
assignments and i don't think you can operate on whole arrays (someone please set me straight if i'm wrong).
#include <iostream.h>
int plantHeights[] = {15,16,17,18,19};
int plantNumbers[] = {2,1,6,4,2};
int product[5];
int count;
for (count = 0; count <= 4; count++)
product[count] = plantHeights[count] * plantNumbers[count];
cout << product[count] << " ";
// not sure, prob'ly won't yield intended result?
document.write( product);

Report •

February 1, 2010 at 06:04:35
nbrane: i've never worked with C++ before
Be thankful. Regardless, it's not C nor C++; it looks like JavaScript.

I'm not about to write someone's homework for them (unless they spend the time convincingly obscuring their question), so I'll just point out what's going wrong.

var count = 1
Arrays are 0 indexed, not 1.

count <= productArray
productArray is never used. I assume you're supposed to store the length of the product array before looping. Also, the arrays are 0 indexed, not 1 indexed.

product = plantHeights * plantNumbers;
I'm assuming you're trying to take the plantHeights element, add the corresponding plantNumbers element to it, and store the result in the relevant product element, but that's not what you're doing. I suggest you reread the chapter in your textbook, or read this page at OpenJS.

Report •

Related Solutions

Ask Question