diff --git a/00HelloWorld/src/solution.js b/00HelloWorld/src/solution.js index 61c3db4..1b36911 100644 --- a/00HelloWorld/src/solution.js +++ b/00HelloWorld/src/solution.js @@ -1,5 +1,9 @@ +// setting up a variable named authorsName with a value of "William Doane" var authorsName = "William E. J. Doane"; +// setting up a function called "greetings" that returns a string consiting of "Hello, " + authorsName var greetings = function () { return "Hello, " + authorsName; -}; \ No newline at end of file +}; + +// if working properly the function should return: Hello, William Doane diff --git a/01DieRoll/src/solution.js b/01DieRoll/src/solution.js index fa1ba50..32df511 100644 --- a/01DieRoll/src/solution.js +++ b/01DieRoll/src/solution.js @@ -1,9 +1,14 @@ +// sets up a variable called authorsName with a value of "William Doane" var authorsName = "William E. J. Doane"; +// setting up a fuction called rollDie that works by using the random function that generates a random number x, where 0 <= x < 1, which is then multiplied by 6 and rounded down. The end result is a number between 0 and 5. Finally, 1 is added so that our range becomes 1 to 6, just like a six sided die. +// var rollDie = function () { return Math.floor(Math.random() * 6) + 1; }; +// setting up a function called main that creates an alert box that displays: You rolled a (the value in rollDie). +// var main = function () { alert( 'You rolled a ' + rollDie() ); }; \ No newline at end of file diff --git a/02GuessingGame/src/solution.js b/02GuessingGame/src/solution.js index 91cd525..88fac92 100644 --- a/02GuessingGame/src/solution.js +++ b/02GuessingGame/src/solution.js @@ -1,17 +1,27 @@ +// setting up a variable named authorsName with a value of "William Doane" +// var authorsName = "William Doane"; +// setting up a fuction called rollDie that works by using the random function that generates a random number x, where 0 <= x < 1, which is then multiplied by 6 and rounded down. The end result is a number between 0 and 5. Finally, 1 is added so that our range becomes 1 to 6, just like a six sided die. +// var rollDie = function () { return Math.floor(Math.random() * 6) + 1; }; +// setting up a variable that returns a prompt: Guess a number from 1 to 6. +// var getUserGuess = function () { return prompt("Guess a number from 1 to 6"); }; +// takes the variable getUserGuess and converts it from a string to a decimal integer. +// var convertToDecimal = function (str) { return parseInt(str, 10); }; +// creates a function called isWinner that checks to see if num and guess are equal to each other. if they are then it returns true else it returns false. +// var isWinner = function (num, guess) { if (num === guess) { return true; @@ -20,15 +30,33 @@ var isWinner = function (num, guess) { } }; +// creates a function called main. +// var main = function () { + +// creates two variables, one called num and one called guess. +// var num, guess; - + +// setting the variable num equal to the number generated by rollDie. +// num = rollDie(); + +// setting the variable guess equal to the value of getUserGuess. +// guess = getUserGuess(); + +// converts the value of guess from a string to a decimal number. +// guess = convertToDecimal(guess); - + +// setting up an if loop that checks to see if num and guess are equal to each other. If they are equal, it creates an alert that tells you that you have won. +// if ( isWinner(num, guess) ) { alert("You win!"); + +// else, it creates an alert that tells you that you were wrong, and what the correct number was. +// } else { alert("Sorry. The answer was: " + num); } diff --git a/03LoopedGuessingGame/src/solution.js b/03LoopedGuessingGame/src/solution.js index 8177e08..b92136d 100644 --- a/03LoopedGuessingGame/src/solution.js +++ b/03LoopedGuessingGame/src/solution.js @@ -1,17 +1,27 @@ +// setting up a variable named authorsName with a value of "William Doane" +// var authorsName = "William Doane"; +// setting up a fuction called rollDie that works by using the random function that generates a random number x, where 0 <= x < 1, which is then multiplied by 6 and rounded down. The end result is a number between 0 and 5. Finally, 1 is added so that our range becomes 1 to 6, just like a six sided die. +// var rollDie = function () { return Math.floor(Math.random() * 6) + 1; }; +// setting up a variable that returns a prompt: Guess a number from min to max. In this case min is 1 and max is 6. +// var getUserGuess = function () { return prompt("Guess a number from 1 to 6"); }; +// takes the variable getUserGuess and converts it from a string to a decimal integer. +// var convertToDecimal = function (str) { return parseInt(str, 10); }; +// creates a function called isWinner that checks to see if num and guess are equal to each other. if they are equal then it returns true else it returns false. +// var isWinner = function (num, guess) { if (num === guess) { return true; @@ -20,19 +30,36 @@ var isWinner = function (num, guess) { } }; +//creates a fuction called main +// var main = function () { + +//creates two variables one called num and one called guess +// var num, guess; +//num is set equal to rollDie function +// num = rollDie(); + +//guess is set equal to getUserGuess function +// guess = getUserGuess(); + +//guess is then set equal to convertToDeimal a.k.a the users guess +// guess = convertToDecimal(guess); +//setting up a while loop that is num and guess are not equal to each other will display an alert message "Try again" and reset the value of guess +// while ( !isWinner(num, guess) ) { alert("Try again."); guess = getUserGuess(); guess = convertToDecimal(guess); } +// else (in this case) if guess and num are equal to each other it will display an alert message "You Win!" +// alert("You win!"); }; \ No newline at end of file diff --git a/04ParameterizedGuessingGame/src/solution.js b/04ParameterizedGuessingGame/src/solution.js index cfb621f..edb0282 100644 --- a/04ParameterizedGuessingGame/src/solution.js +++ b/04ParameterizedGuessingGame/src/solution.js @@ -1,19 +1,35 @@ +// setting up a variable named authorsName with a value of "William Doane" +// var authorsName = "William Doane", - lowest = 1, + +// setting up a variable named lowest with a value of 1 +// + lowest = 1, + +//setting up a variable named highest witha value of 6 +// highest = 6; +// setting up a fuction called rollDie that works by using the random function that generates a random number x, where 0 <= x < 1, which is then multiplied by max and rounded down. The end result is a number between min - 1 and max - 1. Finally, 1 is added so that our range becomes min to max, just like a die with max number of sides. +// var rollDie = function (min, max) { return Math.floor(Math.random() * max) + min; }; +// setting up a variable that returns a prompt: Guess a number from min to max. In this case min is 1 and max is 6. +// var getUserGuess = function (min, max) { return prompt("Guess a number from " + min + " to " + max); }; +// takes the variable getUserGuess and converts it from a string to a decimal integer. +// var convertToDecimal = function (str) { return parseInt(str, 10); }; +// creates a function called isWinner that checks to see if num and guess are equal to each other. If they are then it returns true else it returns false. +// var isWinner = function (num, guess) { if (num === guess) { return true; @@ -22,19 +38,36 @@ var isWinner = function (num, guess) { } }; +// creates a function called main +// var main = function () { + +// creates two variables one called num and one called guess +// var num, guess; - + +// num is equal to rollDie function +// num = rollDie(lowest, highest); + +// guess is set equal to getUserGuess function +// guess = getUserGuess(lowest, highest); + +// guess is then set equal to convertToDecimal a.k.a. the users guess +// guess = convertToDecimal(guess); - + +// setting up a while loop that if num and guess are not equal to each other will display an alert message "Try agian" and reset the value of guess +// while ( !isWinner(num, guess) ) { alert("Try again."); guess = getUserGuess(lowest, highest); guess = convertToDecimal(guess); } +// else (in this case) if guess and num are equal to each other it will display an alert message "You Win!" +// alert("You win!"); }; \ No newline at end of file diff --git a/05UserSpecifiedMinMaxGame/src/solution.js b/05UserSpecifiedMinMaxGame/src/solution.js index f5bc4f1..eeffec7 100644 --- a/05UserSpecifiedMinMaxGame/src/solution.js +++ b/05UserSpecifiedMinMaxGame/src/solution.js @@ -1,27 +1,41 @@ +// setting up a variable named authorsName with a value of "William Doane" +// var authorsName = "William Doane", lowest, highest; +// setting up a fuction called rollDie that works by using the random function that generates a random number x, where 0 <= x < 1, which is then multiplied by max and rounded down. The end result is a number between min - 1 and max - 1. Finally, 1 is added so that our range becomes min to max, just like a die with max number of sides. +// var rollDie = function (min, max) { return Math.floor(Math.random() * max) + min; }; +// setting up a variable that returns a prompt: Guess a number from min to max. In this case min is 1 and max is 6. +// var getUserGuess = function (min, max) { return prompt("Guess a number from " + min + " to " + max); }; +// setting up a variable that returns a prompt: Assign a minimum value to the rollDie function. +// var getUserLowest = function () { return prompt("What is the lowest number I should use?"); }; +// setting up a variable that returns a prompt: Assign a maximum value to the rollDie function. +// var getUserHighest = function () { return prompt("What is the highest number I should use?"); }; +// takes the variable getUserGuess and converts it from a string to a decimal integer. +// var convertToDecimal = function (str) { return parseInt(str, 10); }; +// creates a function called isWinner that checks to see if num and guess are equal to each other. if they are then it returns true else it returns false. +// var isWinner = function (num, guess) { if (num === guess) { return true; @@ -30,25 +44,51 @@ var isWinner = function (num, guess) { } }; +// creates a function called main +// var main = function () { + +// creates two variables one called num and one called guess +// var num, guess; - + +// setting the variable lowest to the value of the variable getUserLowest. +// lowest = getUserLowest(); + +// converts the value of lowest from a string to a decimal number. +// lowest = convertToDecimal(lowest); - + +// setting the variable highest to the value of the variable getUserHighest. +// highest = getUserHighest(); + +// converts the value of highest from a string to a decimal number. +// highest = convertToDecimal(highest); - + +// num is equal to rollDie function +// num = rollDie(lowest, highest); + +// guess is set equal to getUserGuess function +// guess = getUserGuess(lowest, highest); + +// converts the value of guess from a string to a decimal number. +// guess = convertToDecimal(guess); - + +// setting up a while loop that if num and guess are not equal to each other will display an alert message "Try again" and reset the value of guess +// while ( !isWinner(num, guess) ) { alert("Try again."); guess = getUserGuess(lowest, highest); guess = convertToDecimal(guess); } +// else (in this case) if guess and num are equal to each other it will display an alert message "You Win!" alert("You win!"); }; \ No newline at end of file diff --git a/linktocat.png b/linktocat.png new file mode 100644 index 0000000..d1a5025 Binary files /dev/null and b/linktocat.png differ