Answers for "Given a string change the every second letter to an uppercase"

0

Given a string change the every second letter to an uppercase

var str = 'hello world how ya doing?';

function toUpperCase(str) {
  return str.split('').map((v, i) => i % 2 == 0 ? v.toLowerCase() : v.toUpperCase()).join('');
}

console.log(toUpperCase(str));
Posted by: Guest on March-14-2021
0

Given a string change the every second letter to an uppercase

var str = 'hello world how ya doing?';

console.log(toUpperCase(str));

function toUpperCase(str){
  var words = str.split(' ');
  var uppers = words.map(function(val, i) {
    if(i%2 == 0)
      return (val + "").toLowerCase();
    else
      return (val + "").toUpperCase();
  });
  return uppers.join(' ');
}
Posted by: Guest on July-27-2021

Code answers related to "Given a string change the every second letter to an uppercase"

Code answers related to "Javascript"

Browse Popular Code Answers by Language