Saturday, May 1, 2021

Javascript Practice 12: JS Hero - Strings

 
Question: 

Write a function greet having one parameter and returning 'Hello <parameter>!'.

Example: greet('Ada') should return 'Hello Ada!' and greet('Grace') should return 'Hello Grace!'.




Answer: 

function greet (param) {

return 'Hello' + ' ' + param + "!"; 

};

> This is a function declaration & not a function expression 
> name of the function: greet
> parameter: () parameter is param
> statement: return 'Hello' + ' ' + param + "!"; enclosed in curly brackets
> the function must have a return statement that specifies the value to return
> the value type in this case is a string
> strings can be used with single or double quotes
> we can concatenate the string with a '+' sign




No comments:

Post a Comment