Tuesday, May 4, 2021

Javascript Practice 17: JS Hero - Logging and Strings

 
Question:
 
Write a function shout that takes a string and returns this string duplicated. In addition, the return should be logged.

Example: shout('Fire') should return 'FireFire' and should log 'FireFire'.
 
 
 
 
Answer: 
 
function shout (string) {

let x = string + string;
console.log(x);
return x;



> This is a function declaration & not a function expression 
> name of the function: shout
> parameter: () parameter string
> statement: let x = string + string, enclosed in curly brackets
> statement: console.log (x), enclosed in curly brackets 
> statement: return x, enclosed in curly brackets
> created a variable x using let
> concatenated the string parameter and stored it in x
> this function has console.log() to return the function in the console
> console.log method is used to display Javascript values in the browser
> console.log is a function in Javascript
> usually console.log is used for debugging purposes
> in this case the function log, when called, returns / logs the value of the parameter in the console

No comments:

Post a Comment