Trying to create a piece of code that return all numbers below 1000 that are multiples of three. This is the relevant piece of code.
<script>
var i = 1;
var mplesOf3 = [0];
var myNum = 0;
while (myNum < 1000){
(3 * i) = myNum;
mplesOf3.push(myNum);
i++;
};
alert(mplesOf3);
</script>
The code runs in a html page, hence the style tags and alert.
The code basically trying to do 3x1 then 3x2 then 3x3 so on and so forth until the result is over 1000. I came up with the concept days ago and I'm still not sure why its not running properly.
For the record I've seen other solutions to how to do this but because I'm learning and want to improve I want to know why this solution doesn't work.
Thank you in advance
Edit: I should have known the mistake would be something stupid. I wrote (3 x 1) = n on the pseudocode and just didn't spot the mistake because nothing seem wrong to me. Thank to all parties, will accept an answer when I can.
(3 * i) = myNum;Might want to re-check your JS basics and see how assignment works.(3 * i) = myNum;You have this assignment statement backwards. Almost every programming language, including JS, assigns the value of the right side to the left. You're attempting to assign the left side to the right, which is incorrect.