Now remove tags from the code i.e.
// Declaring required variable var digits = "0123456789";
Create a file and give a name like code.js and past above lines which are without tags. Save the file.
Now if this file is in the same root as your webpage then call it in webpage head section like this.
Calling An External JS File