Help with Whale Project inputIndex

Does anyone see why this code loop won’t print the index?

const input = "I've no idea";

const vowles = ["a", "e", "i", "o", "u",]

let resultArray = [];

for (let i = 0; i = input.length; i++){
  console.log( "ii " + inputIndex);
}

looking at the loop:

for (let i = 0; i = input.length; i++)

the i variable holds your index. Yet in the body of the loop, you use an undefined variable

Does this not work ( let i =) It just appears like i should be able to be used as a Variable Name?

the loop is fine, but then within the loop:

console.log( "ii " + inputIndex);

where does inputIndex come from? It hasn’t been defined anywhere

I’m trying to Log the Iterator Number Position…

for which you define a variable i (in loop declaration), yet inside the loop you decide not to use i for reasons unclear to me.

why not use i (which contains your index) in the body of the loop?

Is this right?

const i = "I've no idea";

const vowles = ["a", "e", "i", "o", "u",];

let resultArray = [];

for (let i = 0; i = i.length; i++){
  console.log( "i = " + inputIndex);
}

What did you do? Now you made things worse.

this was better:

const input = "I've no idea";

const vowles = ["a", "e", "i", "o", "u",]

let resultArray = [];

for (let i = 0; i = input.length; i++){
   // body of your for loop
}

so with your loop, you have a variable i, this variable contains your index. So this is what you should use in the bod of your loop:

for (let i = 0; i = input.length; i++){
   console.log(i, input[i]);
}

I am not sure what you think inputIndex is, but to access a string (or array) by index, you need to use square brackets

input index shows how many numbers in your string

Screenshot 2020-11-24 at 13.18.53

This is not the answer its supposed to say,

I should really pay more attention.

You have an infinity loop. How is i = input.length ever going to be false?

I adjust the infinity loop (Lesson Learned) but it still not responding.

const input = "I've no idea";

const vowles = ["a", "e", "i", "o", "u",];

let resultArray = [];

for (let i = 0; i = input.index < input.length; i++){
  console.log( "i =" + input.Index);
};
```I rewrote this and it works now thanks!!

You seem to use a lot of brute-force trail and error. Take your time to learn, and to think about what consequences changed have, and what changes you make and why

Any ideas why this string wont print the results of the loop, It works in the Online Version… And the Error message points at the Loop Variable Name as an Error… But there can’t be an error there, as its only 1 letter. I intentionally simplified it. So I’m stuck,

const input = "I've no idea";

const vowles = ["a", "e", "i", "o", "u",];

let resultArray = [];

for(let inputIndex = 0; inputIndex < input.length; inputIndex++){
  //console.log("inputIndex = " + inputIndex);
}

for(let v = 0; v < vowles.length; v++){
  console.log("vowel =" + v;)
  
}

the code you posted doesn’t match your screenshot.

for the code you posted, the loops aren’t nested

for the screenshot, printing an additional string along with the vowel (loop variable) might not get through SCT.

I think he’s actually calling the loop variable… and that’s why his result is defined. Because the loop defines, his variable… What’s SCT?

SCT = submission correctness test, the part that validates your code against exercise requirements.

Adding additional strings (when the exercise only asks for a number), might trigger errors in SCT. So you should do:

console.log(vowel);

without the additional (vowel = ) string

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.