Buggy script is below.