Pick A Number

Powered by Scriptonite

// Run this page by submitting this url to gemini://ultimatumlabs.com/scriptonite/

function getRandom(min, max) {
    min = Math.ceil(min);
    max = Math.floor(max);
    return Math.floor(Math.random() * (max - min + 1)) + min;
}

function shift(str, offset) {
    return [...str].map(c => String.fromCharCode(c.charCodeAt(0) + offset)).join("");
}

function unshift(str, offset) {
    return [...str].map(c => String.fromCharCode(c.charCodeAt(0) - offset)).join("");
}

function makeGuess(num, attempts){
    print('=> gemini://ultimatumlabs.com/scriptonite/gemini%3A%2F%2Fultimatumlabs.com%2Fpick.gmi;num=' + encodeURIComponent(num) + ';attempts=' + (Number(attempts) + 1) + ';guess:Do%20you%20have%20what%20it%20takes%3F%20Guess%20now. Guess Again');
}

if (typeof num === "undefined") {
    var number = getRandom(1, 100);
    print('\nI have picked a number between 1 and 100. Can you guess it?');
    print('=> gemini://ultimatumlabs.com/scriptonite/gemini%3A%2F%2Fultimatumlabs.com%2Fpick.gmi;num=' + encodeURIComponent(shift(String(number), 3)) + ';attempts=1;guess Enter Your Guess');


} else {
    var number = Number(unshift(num, 3));
    if(!Number.isInteger(Number(guess))){
        print(guess + ' is not a valid number!');
        makeGuess(num, attempts);
    }else if (guess < number) {
        print(guess + ' is too low! Guess again.');
        makeGuess(num, attempts);
    } else if (guess > number) {
        print(guess + ' is too high! Guess again.');
        makeGuess(num, attempts);
    } else {
        print('Correct! It took you ' + attempts + ' tries to guess ' + number + '!');
        print('=> gemini://ultimatumlabs.com/scriptonite/gemini%3A%2F%2Fultimatumlabs.com%2Fpick.gmi Play Again');
    }
}

See The Code