I can't understand where is first word on output..
function camelCase(str){
let string = '';
let arr = str.split(' ');
let oneStr = '';
let twoStr = '';
for (let i = 0; i < arr.length; i++) {
string1 = arr[i] ;
oneStr = string1[0].toUpperCase() + string1.slice(1);
}
return oneStr;
}
console.log(camelCase('camel case'));
Output: Case
Help please to finalize the code
On this line, use += operator to concatenate the strings:
oneStr += string1[0].toUpperCase() + string1.slice(1);
actually you assigned the result to string1 in each iteration, instead use += operator
function camelCase(str){
let string = '';
let arr = str.split(' ');
let oneStr = '';
let twoStr = '';
for (let i = 0; i < arr.length; i++) {
string1 = arr[i] ;
oneStr += string1[0].toUpperCase() + string1.slice(1);
}
return oneStr;
}
console.log(camelCase('camel case'));