modified javascript amazing1 blog answer