Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

java beginner question

Name: hank aaron 2009-03-16 22:00

while programming the game mastermind I became stuck when having to figure out how to come up with the correct integers and i will figure the sum for these after i find them
for example

secretCode = 123

input = 222

output is correct integers: 1 and sum: 2

for input = 122

output is correct integers: 2 and sum: 3

Name: Anonymous 2009-03-17 2:27

var secretCode=genSecret();
var userInput=prompt('Enter number','');
function genSecret(){return Math.floor(Math.random()*10000)}
function checkinp(inp){
var sec=secretCode.toString();var user=inp.toString();var sum=0;var numc=0;
for(var i in user){if(user[i]==sec[i]){numc++;sum+=parseInt(user[i])}}
return 'Correct numbers:'+numc+' Correct numbers sum:'+sum;
}
alert(checkinp(userInput))

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List