i wanna get access to localVariable form another function
(sorry about grammar English is not my main language)
the code:
let Info = {}
function storeInfo(Info) {
let name;
let age;
function getName() {
name = prompt('enter your name:')
}
function getAge() {
age = prompt('how old are you?')
}
getName();
getAge();
Info = {
name:name,
age:age,
}
returnInfo(Info)
}
storeInfo(Info)
function returnInfo(Info) {
return Info.name + ' ' + Info.age;
}
let result = returnInfo(Info);
alert(result)
i wanna returnInfo function get the info of storeInfo function and alert it and the end
>Solution :
I simplified it for you because you made a lot of mess.
- Put the functions as first in code, it will be more clear.
- Try not to mix functions with executable code at the learning stage.
- To use function in function better is to learn about
classes.
Simplified code:
function storeInfo() {
let localFuncInfo = {
name:prompt('enter your name:'),
age:prompt('how old are you?'),
}
return localFuncInfo;
}
function returnInfo(Info) {
return Info.name + ' ' + Info.age;
}
let Info = storeInfo() ;
let result = returnInfo(Info);
alert(result);