Added an alert to test the function for the correct results and it give the desired results.