Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getRandomIntinRange(min, max) {
- min = Math.ceil(min);
- max = Math.floor(max);
- return Math.floor(Math.random() * (max - min + 1)) + min;
- }
- let DEFAULT_END_OF_PROGRAM_MESSAGE = "end of program";
- let DEFAULT_WRONG_COMMAND_MESSAGE = "the fuck are you typing";
- let DEFAULT_STRING_MIN_SIZE = 5;
- let DEFAULT_STRING_MAX_SIZE = 8;
- let DEFAULT_LETTER_A_POSITION = 65;
- let DEFAULT_LETTER_Z_POSITION = 90;
- let lettersArray = [];
- let numbersArray = [];
- for (let i = DEFAULT_LETTER_A_POSITION; i <= DEFAULT_LETTER_Z_POSITION; i++) {
- lettersArray.push(String.fromCharCode(i));
- }
- for (let i = 0; i <= 9; i++) {
- numbersArray.push(i);
- }
- let answer = prompt('', 'next');
- if (answer === "end") {
- console.log(DEFAULT_END_OF_PROGRAM_MESSAGE);
- } else {
- let currentString = [];
- let currentStringSize;
- let currentCharType;
- while (answer === "next") {
- currentStringSize = getRandomIntinRange(DEFAULT_STRING_MIN_SIZE, DEFAULT_STRING_MAX_SIZE);
- for (let i = 0; i <= (currentStringSize - 1); i++) {
- currentCharType = Math.floor((Math.random() * 2));
- if (currentCharType === 0) {
- currentString.push(lettersArray[getRandomIntinRange(0, (lettersArray.length - 1))]);
- } else {
- currentString.push(numbersArray[getRandomIntinRange(0, (numbersArray.length - 1))]);
- }
- }
- console.log(currentString.join(""));
- currentString = [];
- answer = prompt('', 'next');
- if (answer === "end") {
- console.log(DEFAULT_END_OF_PROGRAM_MESSAGE);
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement