Skip to content
6 changes: 5 additions & 1 deletion 00HelloWorld/src/solution.js
Original file line number Diff line number Diff line change
@@ -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;
};
};

// if working properly the function should return: Hello, William Doane
5 changes: 5 additions & 0 deletions 01DieRoll/src/solution.js
Original file line number Diff line number Diff line change
@@ -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() );
};
32 changes: 30 additions & 2 deletions 02GuessingGame/src/solution.js
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
}
Expand Down
27 changes: 27 additions & 0 deletions 03LoopedGuessingGame/src/solution.js
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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!");

};
39 changes: 36 additions & 3 deletions 04ParameterizedGuessingGame/src/solution.js
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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!");

};
48 changes: 44 additions & 4 deletions 05UserSpecifiedMinMaxGame/src/solution.js
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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!");

};
Binary file added linktocat.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.