Declare JavaScript Objects as Variables

Tell us what’s happening:
What happens if you set the first one to 3? and if you set the second one to zero?

Your code so far

var fruits = ['apple', 'pear', 'mango', 'orange', 'banana'];

// create an empty list for fruits ending with 'e'
var efruits = [];
for (var i=0;i<fruits.length;i++){
    var fruit = fruits[i];
    //check if the current fruit end with 'e'    
    if (fruit.endsWith('e')){
        // add fruit ending with 'e' to the list
        efruits.push(fruit);
    }
}

var multiplesOfThee =0;
for (var i=1;i<=300;i++){
    if (i % 3 === 0){
        multiplesOfThee -= '4'//i; 
      console.log(multiplesOfThee);
    }
}
//console.log('4');

var motorBike = {

  // Only change code below this line.

};

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36.

Link to the challenge:
my personal challenge

“first one” refers to first variable, just to make sure you know.

This is to ensure I know how a loop works.

I’ve edited your post for readability. When you enter a code block into the forum, precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

markdown_Forums

Hi, are you available?

I’m on my phone right now, so I can’t manipulate code easily. It looks like you are just asking about what happens if you change either arguments or internal values (I wasn’t sure).

What happened when you tried it? How did it behave differently than you expected? What part doesn’t make sense?

I was asking what would happen if you changed the 1 to a 3 (in the one about doing 300 iterations), would that start on the third iteration?
The iterations would look like this:
before it runs
first 3
second 9 (3+6)
third 15 (this would be 6+9) —this is where it would start?

Does that sound correct?

Why ask other people what would happen instead of just changing it and seeing what happens?

Because I’m confirming what I see. Sometimes I can atttribute causal factors that are actually not causal factors. At this stage, for me to understand everything else later on, I need to make sure that I’m on the right trajectory.

Try it. See what happens. See if you understand why it happens. If you’re not sure that you understand what is happening or why, come and discuss it with us.

This question is just making sure I understand whats going on but I found that the += iterator makes it add on to the previous one. Does the ± one make it subtract in this way:
-3
-9 what it is considering:-3-6
18 what it is considering:-6-9

etc.

Im trying to understand iterators a little better

That wasn’t my intention. I meant to refer to the += and the -= variables and specifically what they do in a for loop

var multiplesOfThreeSums = 0;
var numberCounter = 0;
for (var i=1;i<=300;i++){
if (i % 3 === 0){
numberCounter++;
multiplesOfThreeSums += i;
}
}

The above adds sums 300 times. How would I subtract 300 times from a starting number?

You did not specify what the starting number should be or what value you wanted to subtract 300 times from the starting number, so I made up my own values.

var number = 2000; // starting number
var subtractThis = 5; // a number you want to subtract 300 times from the starting number

for (var i=1;i<=300;i++){
  number -= subtractThis;
}
console.log(number); // displays 500