Hi Guys,
Just after a bit of feedback on my project. I appreciate i could have probaly done things quicker and easier but wanted to try out different things and options.
Thank you for looking.
Hi Guys,
Just after a bit of feedback on my project. I appreciate i could have probaly done things quicker and easier but wanted to try out different things and options.
Thank you for looking.
Hi, I’ve read through your code and have some feedback, bearing in mind I’m only learning as well.
You could simplify getWindSpeed() by making those multipliers values of a windSpeedMultiplier key on the seasonInfo object. Then you can get rid of all the if/else statements and just have:
const getWindSpeed = (todaysSeason) => {
return Math.floor(Math.random() * todaysSeason.windSpeedMultiplier);
}
The other thing I noticed is that there are quite a few variables declared in the global namespace, which is something I understand is a good practice to avoid. For instance, the seasonInfo object should be declared inside the getSeason() function since it is referenced nowhere else in the code. Wind direction has not been encapsulated in a getWindDirection() function, nor has the weather section, and both probably should be, although I’m assuming this is an oversight since you did do that for the rest of the variables.
Another way of doing the temp to make it more concise would be:
const getTemp = (todaysSeason) => {
const tempRange = todaysSeason.tempHigh - todaysSeason.tempLow
return Math.floor(Math.random() * tempRange) + todaysSeason.tempLow
}
Although it doesn’t affect the functionality of your code, rather than removing items from your weatherOptions array, I think the code would be more readable if you did the opposite and added options like misty and snowy to the base array instead. It also reduces the potential for errors if the code is updated to include more weather options at a later date.
Finally, on the subject of readability, you currently call each function and assign it to a variable immediately after declaring it. I think it would be an improvement to group all of those variable assignments together at the end of the script so that it’s clear what all of the variable required for the final output are and where they came from.
And that’s all, I tried to be thorough because that’s what I’d want someone to do for my shared code, so I hope some of this is helpful.