3
JS Assignment 8: Scope and the Return Statement
skudeva (8)

Hi everyone,

I just started learning JS so I am still pretty new at this. I've been struggling with the JS Assignment 8: Scope and the Return Statement (pre-course work) exercise #3. Please if anyone knows the answer explain how do I get it, that'd be highly appreciated!

// Exercise Three:
// Create a function called 'sayMyName'. It will take one parameter. Call this
// parameter 'myName'. Return the phrase "Hello, my name is " and the myName parameter.
// eg: if name is 'Dan' it should return the string: 'Hello, my name is Dan'.

let myName ="Dan";
function sayMyName(myName){
return "Hello, my name is"; 

}
sayMyName();

https://repl.it/student/submissions/6895228

Thank you!

You are viewing a single comment. View All
Answered by JustARatherRidi (185) [earned 5 cycles]
View Answer
1
Shif (1)

I'm new here too, but I struggled through this and happy to share my solution:

The key was to declare a new Var that would include the "Hello..." in this case:
let printName = ("Hello, my name is " + myName);

making sure to include a return statement for that new Var:
return printName;

And finally: calling the function passing in your name as an argument:

sayMyName('Shifra');

function sayMyName(myName){
  let printName = ("Hello, my name is " + myName);
  return printName;
}

sayMyName('Shifra');