for loop with if statement javascript code example
Example 1: javascript loop if statement
for (let i = 0; i < 10000; i++) {
console.log('huduiduin 100000 times');
}
Example 2: for of loop syntax javascript
for (let step = 0; step < 5; step++) {
console.log('Walking east one step');
}
Example 3: how to make an if statement in javascript
if(condition1) {
}else if (condition2) {
} else {
}
Example 4: javascript loop and if statement
function LetterCapitalize(str) {
var output = ""+str.charAt(0).toUpperCase();
for(var i=1; i < str.length; i++){
if(str.charAt(i - 1) == " ") {
output += str.charAt(i).toUpperCase();
} else {
output += str.charAt(i);
}
}
return output;
}
console.log(LetterCapitalize("hello world"))