Apply the map() function to the variable str
so that every second word in the string is converted to uppercase. in javascript.
str = "hello my name is jon and i live in. canada."
Apply the map() function to the variable str
so that every second word in the string is converted to uppercase. in javascript.
str = "hello my name is jon and i live in. canada."
"hello my name is jon and i live in. canada."
.split(" ")
.map((word, idx) => idx % 2 === 0 ? word : word.toUpperCase())
.join(" ")
The trick is:
toUpperCase()
if idx % 2 !== 0
.join
back with spaces.