Tuesday, May 4, 2021

Javascript Practice 20: JS Hero - String: toUpperCase()

 
Question: 
 
Write a function toCase that takes a string and returns that string in lowercase and uppercase with - as delimiter.

Example: toCase('Mthatha') should return 'mthatha-MTHATHA'.
 
 
 
 
Answer: 
 
function toCase (string) {

return string.toLowerCase() + '-' + string.toUpperCase();

};
 
> function name is toCase
> it is a function expression
> parameter is string
> statement is
return string.toLowerCase() + '-' + string.toUpperCase(); enclosed in curly brackets
> this function returns a statement that will return the argument / parameter - 'string' converted in lower & upper case
> the return statement concatenates the upper and the lower cases using the '+' sign and a delimiter

No comments:

Post a Comment