javascript indexOf()
Go to solution
Solved by 79wjd,
11 minutes ago, shooter2749 said:so I have to show every month with the letter R in it (month is "mois" in french, all the month name are in french sorry)
I think I got it right but for some reason it displays all the months idk why
var mois =['Janvier','Février','Mars','Avril','Mai','Juin','Juillet', 'Aout','Septembre','Octobre','Novembre','Décembre']; for(var i =0;i<mois.length;i++) { if(mois[i].indexOf('r')) { document.writeln(mois[i]) } }
The if branch will always be taken. You need to make it:
if (mois[i].indexOf('r') >= 0)
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now