I cant have access to my variables from my function UserInfo
all my variables are undefined. How can I have access to my variable and display them in my func
The issue with your code is the scope of the variables. In javascript, all variables declared with let
have block scope. And you are redeclaring them inside your UserInfo
function, so you should just use the variables you had already declared.
let UserName;
let UserAge;
let UserBirthPlace;
let UserDream;
let UserInfo = function() {
UserName = prompt("What is your name:");
UserAge = prompt("How old are you: ");
UserBirthPlace = prompt("Where were you born: ")
UserDream = prompt("What is your Greatest Dream: ");
}
let seeInfoUser = function() {
let UserInformation = ` ${UserName} is ${UserAge} and he was born in ${UserBirthPlace} and his greatest dream is ${UserDream}`
return UserInformation
}
let result = seeInfoUser(UserInfo());
console.log(result)