Burger King or McDonalds

Settings
close
Items   Rows

Features of this Burger King or McDonalds Decision Maker

  • Lets you decide between multiple choices of Burger King, McDonalds and more
  • Change or add your custom choices
  • Start and Stop the decision maker at your own will

Javascript code for this Random Decision Maker

How to code a random generator that selects a choice between Burger King or McDonalds

Here is the code for a JS Decision Maker that randomly selects from the list of following options: Burger King,McDonalds


    // Burger King or McDonalds
        
        // a list containing the options
        var list = ['Burger King', 'McDonalds'];

    
                   
        // define the range of numbers to pick from
        var lowest = 0;             // lowest possible index of the list
        var highest = list.length-1;           // highest possible index of the list
        var number_of_decisions = 1;    // how many decisions to make   

        var this_decision = []; // array to store the results of this decision

        for (var j = 1; j <= number_of_decisions; j++) {

            // loop for the number of decisions

            // for each decision, generate a number between lowest and highest indices of the list
            var decision_number = Math.floor(Math.random() * (highest-lowest+1) + lowest);

            this_decision.push(list[decision_number]); //store this decision in the array
        }
            

        // print all the generated decisions
            
        for (j = 0; j < this_decision.length; j++) {

            // loop through the decision array 

            //print each decision value followed by a comma
            document.write(this_decision[j]);
            document.write(", ");

        }
            
        
    

    /* 

    Sample output 

    

    */
    


...