Today, I told my students about software project management. I found that students want to go to bed and have the opportunity to give them a small game to guess about it ~ Simple: Example source code: viewplaincopytoclipboardprint? & Lt ;! DOCTYPEhtmlPUBLIC & quot;-// W3C // DTDXHTML1.0. .. SyntaxHi
Today, I told my students about software project management. I found that students want to go to bed and have the opportunity to give them a small game to guess about it ~
Simple:
Sample source code:
View plaincopy to clipboardprint?
Guess
Script
// Generate a random integer
// Rounding a random number (0-1)
Var num = Math. round (Math. random () * 1000 );
// Define a flag variable
Var falg = true;
// Define a variable to count the number of guesses
Var count = 1;
Document. write ("
");
// Execute the while LOOP
While (falg ){
If (count <= 10 ){
// Step 1: accept the content entered by the user
Var inputnum = prompt ("Enter the number you want to guess! ", 1 );
// Step 2: Compare the user input content with the generated Random Number
// Three cases: 1) if the input number is greater than the random number, the system prompts "large"
If (inputnum> num ){
// Output a sentence,
Document. write ("this is your" + count + "opportunity. The number you entered this time is" + inputnum + ". The number you entered is large.
");
Count ++;
}
// Three cases: 2) if the number of inputs is smaller than the number of random numbers, the system prompts "smaller"
If (inputnum // Output a sentence,
Document. write ("this is your" + count + "opportunity. The number you entered this time is" + inputnum + ". The number you entered is smaller.
");
Count ++;
}
// Three cases: 1) if the number of inputs is equal to the number of random numbers, the system prompts "yes" and sets the flag to false;
If (inputnum = num ){
If (count <= 3 ){
// Output a sentence,
Alert ("You are amazing, you guessed it! ");
}
If (count <= 6 & count> 3 ){
// Output a sentence,
Alert ("You can, but you guessed it! ");
}
If (count <= 10 & count> 6 ){
// Output a sentence,
Alert ("barely, that's right! ");
}
// Set the flag to false.
Falg = false;
}
} Else {
// Output a sentence,
Alert ("I'm dizzy. I haven't guessed it for 10 times. Why ?! ");
// Set the flag to false.
Falg = false;
}
}
Script
Guess
Script
// Generate a random integer
// Rounding a random number (0-1)
Var num = Math. round (Math. random () * 1000 );
// Define a flag variable
Var falg = true;
// Define a variable to count the number of guesses
Var count = 1;
Document. write ("
");
// Execute the while LOOP
While (falg ){
If (count <= 10 ){
// Step 1: accept the content entered by the user
Var inputnum = prompt ("Enter the number you want to guess! ", 1 );
// Step 2: Compare the user input content with the generated Random Number
// Three cases: 1) if the input number is greater than the random number, the system prompts "large"
If (inputnum> num ){
// Output a sentence,
Document. write ("this is your" + count + "opportunity. The number you entered this time is" + inputnum + ". The number you entered is large.
");
Count ++;
}
// Three cases: 2) if the number of inputs is smaller than the number of random numbers, the system prompts "smaller"
If (inputnum // Output a sentence,
Document. write ("this is your" + count + "opportunity. The number you entered this time is" + inputnum + ". The number you entered is smaller.
");
Count ++;
}
// Three cases: 1) if the number of inputs is equal to the number of random numbers, the system prompts "yes" and sets the flag to false;
If (inputnum = num ){
If (count <= 3 ){
// Output a sentence,
Alert ("You are amazing, you guessed it! ");
}
If (count <= 6 & count> 3 ){
// Output a sentence,
Alert ("You can, but you guessed it! ");
}
If (count <= 10 & count> 6 ){
// Output a sentence,
Alert ("barely, that's right! ");
}
// Set the flag to false.
Falg = false;
}
} Else {
// Output a sentence,
Alert ("I'm dizzy. I haven't guessed it for 10 times. Why ?! ");
// Set the flag to false.
Falg = false;
}
}
Script
If you are interested, study it ~
Author: "liweiw.job column"