I'm working on an app on Code.org using JavaScript that is supposed to calculate the mean of a set of numbers. However, when I run the code, it keeps returning NaN (Not a Number). I would really appreciate any help in fixing this issue! Here's the link to my code: https://studio.code.org/projects/applab/1522b2c0-0d50-4585-926b-1def392a2abb.
3 Answers
It sounds like you're trying to do your calculations too early in your code. You need to make sure the code that fetches the numbers runs after the user hits the Calculate button. Instead of having things like `var num1 = getNumber("dropdown1")` at the start, move that into the `onEvent("calcBtn", "click", ...)`. Also, avoid declaring variables like `var unused = unused;` because that will mess up your calculations since `unused` won't be set correctly. Try starting with finding the mean of just two numbers before expanding to more.
You definitely want to restructure how you set up your variables inside your event functions. Take your time and build step by step, starting with handling a small number of inputs before scaling it up. It’s easier to troubleshoot that way!
A quick tip: Make sure that you initialize your `unused` variable to something meaningful like zero instead of referencing it before setting it. If you do 'unused = unused' first, it will cause it to return null or something unexpected, which leads to NaN when you calculate the mean.

Related Questions
How To: Running Codex CLI on Windows with Azure OpenAI
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically