Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascritp

import java.util.Scanner;

public class practice8 {
    public static void main(String[] args) {
        int num1 = (int) (Math.random()*100);
        int num2 = (int) (Math.random()*100);
        Scanner s = new Scanner(System.in);
        System.out.print("what is " +num1+ " -"+num2 + " ? ");
        int answer = s.nextInt();
        int counter = 0;
        boolean anw = num1-num2==answer;
        if (anw) {
            System.out.println("correct");
            counter++;
        } else {
            System.out.printf("incorrect! the answer is %d ",num1-num2);
            
        }
        do {
            if (!anw) {
                break;
                
            }
         num1 = (int) (Math.random()*100);
         num2 = (int) (Math.random()*100);
        System.out.println("what is " +num1+ " -"+num2 + " ? ");
         answer = s.nextInt();
         anw= num1-num2==answer;
         if (anw) {
            System.out.println("correct");
            counter++;
         } else {
            System.out.printf("incorrect! the answer is %d ",num1-num2);
            
         }   
        } while (anw);
        System.out.println();
        System.out.println("you had " + counter + " guess! ");
    }
    
}
Source by github.com #
 
PREVIOUS NEXT
Tagged: #javascritp
ADD COMMENT
Topic
Name
3+9 =