how to use a loop to cap the last letter of a string

let x = "hello my name is chrono" let reg = x.split(' ') for(let i = 0; i < reg.length; i++) {

reg[i] = reg[i][0].toUpperCase() + reg[i].substr(1)
} reg.join(" ") console.log(reg) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> The code above is to change the first letter of the string to uppercase. The next lesson is to change the last letter instead of the first Please help
8 Replies
Jochem
Jochem•3y ago
that isn't changing the first letter of the input string, but the first letter of every word in the input string, is that what you want? also, what are you stuck with? We're here to help, but not to write your homework assignments for you, and this really sounds like it's a homework assignment
chrono1913
chrono1913•3y ago
the code I pasted there was to cap the first letter of every words in the string, I want now to make all the last letter of every word cap also thanks for responding
Jochem
Jochem•3y ago
chrono1913
chrono1913•3y ago
I can use regex and other method but the exercise is to use loop is there a way I can use loop to target the last letter?
Jochem
Jochem•3y ago
I think trying to figure that out is part of the assignment, right?
chrono1913
chrono1913•3y ago
ya part one was to are that first part I was thinking for the loop for(let i = reg.length - 1; i < 0; i++) but its not caping anything with that
Jochem
Jochem•3y ago
you've got the i<0 the wrong way around 🙂 i needs to be greater than zero, not less
chrono1913
chrono1913•3y ago
i tried that too but it still didn’t work, maybe i need to push() the value let x = "hello my name is chrono" let reg = x.split(' ') for(let i = 0; i < reg.length; i++) { reg[i] = reg[i].substr(0, reg[i].length - 1) + reg[i][reg[i].length - 1].toUpperCase()

} reg.join(" ") console.log(reg) I figured it out lol
Want results from more Discord servers?
Add your server