I think the link to the final solution is wrong. Would you mind double checking this?
Just a quick recommendation from my side, even though Iâm usually not involved in this. However, I just felt like doing a code review
If Discourse didnât screw up with the formatting, I think the indentation is not quite correct on the last if (looks way better than the first iteration though!). The last paranthis should be on the same level as the âifâ and you could get rid of the two empty lines between. The same goes with the first empty line in the âwhileâ. These are minor things, but make it way easier to understand the code quicker by developers working on the same code base.
Now letâs look at the code itself and the logic. Iâm not aware of the assignment, but I think this is a counter that changes and counts down on every line, right? If my assumption is true, I have the following feedback:
- As para is a variable holding the first âCountdownâ textContent, Iâd suggest to use a new variable in the while to not override it. As it is, there is no sideeffect, but with a more complex task you might assume that the para variable is still what you assigned it to be
- I think it might be faster (just a few ms or less) to set the .textContent before you append it to the output (would need to test this with a few million iterations) but Iâm quite sure. This way the browser doesnât need to render the whole thing again after adding it to the DOM. However, there might be engine optimizations exactly for that.
- You donât need the if statement below the while. You will be within the while loop as long as i>=0 holds true. Once that is not the case anymore (i=-1) the while loop is left and the other code gets executed. The i === 0 check will never hold true as it will always be -1. So you can leave out the whole check.
- Itâs nice to save the âBlast offâ text in a variable, however that needs to be done with care. Any variable assignment that doesnât have a âvarâ in front of it, is assigned to the global scope. This means that you would potentially overwrite any âinfoâ variable that exists on the website, including any browser-provided variables there are on the âwindowâ object. This could also be a, uncareful written, variable from another framework your website uses. More info
Happy to help further, I was looking for a possibility to improve my code reviewing skills
Cheers,
Michael