Get variable data out of lower scope
I am making an online app for practicing math problems for kids. (code is below)
I declare multiAns inside of the function submitAnswer
```
function submitAnswer() {
let multiAns = Number(document.getElementById("wsf-2-field-115").value)
Number(document.getElementById("wsf-2-field-115").value)
const displayAnswer = `<span>${multiNum1} X ${multiNum2} =
${multiAns}</span>
<br>`
resultsBlock.innerHTML += displayAnswer
}
```
It gets its value from a form submission
```
multiAnsForm.addEventListener("submit", function(event) {
event.preventDefault()
submitAnswer()
console.log(multiAns = "multiAns")
newFactors()
})
```
But I can not get that outside of the function. It makes sense because of scoping. I have tried declaring the variable globally and then reassign it in the function. But I still did not get the data that was reassigned in the function.
I need the information in that variable so that I can create another function that compares the given answer with the correct answer and then do something depending on if the answer was correct.
Can anyone shed some light on this for me?
I know this is remedial, but I am just not understanding this properly.
Thank you!