Changed the for loop so that it will detect whether an input is a valid number or not by adding isNaN inside the first for loop.