I\'m trying to convert a character in an array to uppercase using .toUpperCase(), but it doesn\'t work. I\'m pretty sure my logic is correct, so not sure why it\'s not working?<
The above answer is correct, however I slightly modified the code you wrote, as things can be achieved without using arrays.
var test = "hello*3";
LetterChanges(test)
function LetterChanges(str) {
var newStr = ""
for (i = 0; i < str.length; i++) {
var ch = str[i];
if(ch >='A' && ch<='z'){
ch = String.fromCharCode(ch.charCodeAt(0) + 1);
if(ch == 'p' || ch == 'i')
ch = ch.toUpperCase();
}
newStr += ch;
}
console.log(newStr);
return newStr;
}
Here is the fiddle : https://jsfiddle.net/fzme18q0/2/
console.log(tempArr[i]); //this will display "i" and "p".. why?
because you were not storing the converted value back to the variable
make it
tempArr[i] = tempArr[i].toUpperCase();