xxxxxxxxxx
92
var promptnumber = 0
var randnum = 0
var yay
var randomnum = 0
var calcorno
var urnum
var currentguess
var maxnumpro = 0
var idk
var yn = 0
var sound
var yn2 = 0
function preload(){
sound = loadSound("Guessed.mp3")
}
function setup() {
createCanvas(400, 400);
frtcont()
promptnum()
maxnumhuh()
}
function frtcont(){
frameRate(prompt("What speed should the computer guess at? Please type in a number from 1 to 60"))
}
function promptnum(){
promptnumber = window.prompt("Number between 1 and 1, 000, 000? This is the number that is going to be guessed. It must be a whole number")
}
function promptnum2(){
const idk = `Try again. I said a number between 1 and 1, 000, 000 and you gave ${promptnumber}`
promptnumber = window.prompt(idk)
}
function maxnumhuh(){
maxnum = prompt("What will be the maximum number? (please don't make it too large but make it larger than the number that is going to be guessed)")
}
function maxnumhuh2(){
const maxnumpro = `The maximum number has to be larger than the number guessed, which was ${promptnumber} .Try again...`
maxnum = prompt(maxnumpro)
}
function draw() {
if (maxnum < promptnumber){
maxnumhuh2()
}
if (yn == 1){
const urnum = `Your number is ${promptnumber}`
text(urnum , 50, 10)
}
const currentguess = `The computers current guess is in the console.`
text(currentguess, 50, 20)
randomnum = floor(random(0, maxnum))
console.log(randomnum)
if (promptnumber > 0){
if (promptnumber < maxnum+1){
yn = 1
if (promptnumber == randomnum){
frameRate(0)
const yay = `It took the computer ${frameCount} guesses to guess your number!`
text(yay, 50, 60)
}
if (promptnumber != randomnum){
text(calcorno, 50, 50)
}
}
else if (promptnumber > maxnum){
promptnum2()
}
}
else if (promptnumber < 1){
promptnum2()
}
if (mouseIsPressed){
if (keyCode == 77){
yn2++
}
}
if (yn2 > 180){
if(mouseIsPressed){
if(keyCode == 69){
yn2++
if(yn2 == 240){
sound.play()
}
}
}
}
}