Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds instruction to assignment #2

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
150 changes: 118 additions & 32 deletions exercises.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
/*
If statements - Evaluates (or checks) a condition. If the condition is true, any statements in the subsequent code block are executed
*/
var today = new Date();



/*var today = new Date();

if(today === "Friday"){
return "Let's Party!";
};
};*/

/*
If/else statements = Evaluates (or checks) a condition. If the condition is true, the first code block is executed. If the condition is false, the second code block is executed instead.
*/

if(today === "Friday"){
/*if(today === "Friday"){
return "Let's Party!";
}else{
return "Get back to coding!";
};
};*/



/*
Expand All @@ -29,6 +33,17 @@ if(today === "Friday"){
* The function will return true if the number passed into the function is equal to or greater than Hawaii's voting age. Console.log your result.
*/

function canVote(age){
if (age >= 18){
return true;
} else {
return false;
}
}

console.log('canVote:', canVote(15));
console.log('canVote:', canVote(19));


/*
* #2
Expand All @@ -42,6 +57,17 @@ if(today === "Friday"){
* Console.log your result.
*/

function login(password){
if(password === 'test1234'){
return 'Login Success!';
} else {
return 'Login Fail!';
}
}

console.log('login:', login('test1234'));
console.log('login:', login('test4321'));


/*
* #3
Expand All @@ -56,6 +82,16 @@ if(today === "Friday"){
* Console.log your result.
*/

function isGreaterThan(first, second){
if(first > second){
return true;
} else {
return false;
}
}

console.log('Is Greater Than:', isGreaterThan(2,1));
console.log('Is Greater Than:', isGreaterThan(1,2));

/*
* #4
Expand All @@ -69,6 +105,17 @@ if(today === "Friday"){
* Console.log your result.
*/

function mustbeTrue(boo){
if(boo === true){
return true;
} else {
return false;
}
}

console.log('mustbeTrue:', mustbeTrue(true));
console.log('mustbeTrue:', mustbeTrue(false));


/*
* #5
Expand All @@ -78,10 +125,20 @@ if(today === "Friday"){
* @param Datatype: String `word`
* @return Datatype: String
*
* The function will return the message "Word to Big Bird!", if the string passed into the function is a three-letter word.
* The function will return the message "Word to Big Bird!", if the string passed into the function is a three-letter word.
* Console.log your result.
*/

function bigBird(word){
if(word === word.substring(0,3)){
return 'Word to Big Bird';
} else {
return 'Nah';
}
}

console.log(bigBird('che'));


/*
* #6
Expand All @@ -92,7 +149,7 @@ if(today === "Friday"){
* @param Datatype: String `second`
* @return Datatype: String
*
* If the strings are equal, the function will return the message "You look mahvelous!" Otherwise, return the message: "I don't know who you are anymore."
* If the strings are equal, the function will return the message "You look mahvelous!" Otherwise, return the message: "I don't know who you are anymore."
* Console.log your result.
*/

Expand All @@ -106,7 +163,7 @@ if(today === "Friday"){
* @param Datatype: String `second`
* @return Datatype: String
*
* If the strings are not equal, the function will return the message "Opposites do attract." Otherwise, return the message: "Cause it's like you're my mirror."
* If the strings are not equal, the function will return the message "Opposites do attract." Otherwise, return the message: "Cause it's like you're my mirror."
* Console.log your result.
*/

Expand All @@ -121,7 +178,7 @@ if(today === "Friday"){
*
* The function will return true if the number passed into the function is greater than 100, otherwise it will return false.
* Console.log your result.
*/
*/


/*
Expand All @@ -136,7 +193,7 @@ if(today === "Friday"){
*
* The function will return true if the sum of all the number values is greater than 30, otherwise it will return false.
* Console.log your result.
*/
*/


/*
Expand All @@ -149,7 +206,7 @@ if(today === "Friday"){
*
* The function will return true if the number passed in is an even integer, otherwise it will return false.
* Console.log your result.
*/
*/


/*
Expand All @@ -163,7 +220,7 @@ if(today === "Friday"){
*
* If BOTH values are 21 or over, the function will return the message: "Welcome to the Legends Lounge." Otherwise, it will return the message: "Chuck E Cheese is across the street."
* Console.log your result.
*/
*/


/*
Expand All @@ -177,7 +234,7 @@ if(today === "Friday"){
*
* If EITHER the number value is greater than or equal to 120 or the boolean value is true, then the function will return the message: "Congratulations on a job well done." Otherwise, return the message: "See you in summer school."
* Console.log your result.
*/
*/


/*
Expand All @@ -190,7 +247,7 @@ if(today === "Friday"){
*
* The function will return the message: "You are riding Honolulu's Rail.", if the number value is less than 50, otherwise it will return the message: "You are riding an Amtrak.", if the number value is less than 100, and return the message: "Now you ballin' in the Shinkansen!", if the number value is greater than or equal to 100.
* Console.log your result.
*/
*/


/*
Expand All @@ -202,10 +259,31 @@ if(today === "Friday"){
*
* Create a function named `buyDoughnut` which takes NO parameters.
* When the function is invoked, the budget will be decreased by the doughnutPrice and doughnutBought will increase by 1.
* Your function should return a message 'Not enough money' if you run out of money in your budget
* Console.log budget and doughnutBought.
* Invoke your function again.
* Console.log budget and doughnutBought again.
*/
*/

var budget = 20;
var doughnutPrice = 5;
var doughnutBought = 0;

function buyDoughnut(){
if (budget >= doughnutPrice){
budget = budget - doughnutPrice;
return doughnutBought++;
} else {
return 'not enough funds';
}
}

console.log(budget);
console.log(doughnutBought);
buyDoughnut();
console.log(budget);
console.log(doughnutBought);



/*
Expand All @@ -225,7 +303,7 @@ for (var i = 0; i<toyotaModels.length; i++){
}


/*
/*
* #15
* Create a for loop that will iterate 5 times and console.log the following:
* "Player: 1"
Expand All @@ -236,7 +314,7 @@ for (var i = 0; i<toyotaModels.length; i++){
*/


/*
/*
* #16
* Create a for loop that will iterate and console.log each item in the array below:
*/
Expand All @@ -248,12 +326,12 @@ for (var i = 0; i<toyotaModels.length; i++){
* Function - sumItUp
* Declare a variable named `numArray` and assign it with an array of 5 random numbers of your choice.
* Declare a variable named `total` and assign it with a number value of 0.
*
*
* Create a function named sumItUp which takes a parameter: `arr`.
*
*
* @param Datatype: Array `arr`
* @return Datatype: Number
*
*
* The function will loop through and add up all the values in the array that is passed into the function and return the total.
* Console.log your result.
*/
Expand All @@ -269,12 +347,18 @@ for (var i = 0; i<toyotaModels.length; i++){
*
* The function will loop through the players array and will put all the even number indexed players in the `east` array and the rest in the `west` array.
* Console.log both the east and west arrays.
*/
*/

var players = ["LeBron", "Linsanity", "Kawhi", "Kobe", "Yao Ming", "Bird", "Jordan"];
var east = [];
var west = [];

function allStars(ballers){
for (var i = 0; i < ballers.length; i++) {

}
}

/*
* #19
* Function - subways
Expand All @@ -285,7 +369,7 @@ for (var i = 0; i<toyotaModels.length; i++){
*
* The function will loop through the array value and replace all the odd numbered indexed items with "Classic Tuna".
* Console.log your results.
*/
*/

var subOftheDay = ["Teriyaki Chicken", "Spicy Italian", "Turkey", "BMT", "Black Forest Ham", "Meatball Marinara", "Veggie"];

Expand All @@ -294,23 +378,25 @@ for (var i = 0; i<toyotaModels.length; i++){
Final Boss
* #20
* Function - removeLetter
* Create a function named `removeLetter`, which takes a parameter `str`.
* Create a function named `removeLetter`, which takes a parameter `str`.
*
* @param Datatype: String `str`
* @return Datatype: Array
*
* The function will loop through the string value and put all the letters into an array, except for the letter "A" and "a". We don't want no stinking "A" or "a" in our array. Test your function with the `phrase` below!
*/

var phrase = "An apple a day keeps Alice feeling awesome!"









var phrase = "An apple a day keeps Alice feeling awesome!";

function removeLetter(str){
var newArr = [];
for (var i = 0; i < str.length; i++){
if (str[i] != 'a' && str[i] != 'A'){
newArr.push(str[i]);
}
}
console.log(newArr);
return newArr;
}

removeLetter(phrase);
18 changes: 18 additions & 0 deletions random.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
var students = [
'Christine',
'Jacob',
'Anthony',
'Earnest',
'Ann',
'Ella',
'James',
'Joshua',
'Kaleo',
'Ulu',
'Gaganvir'
];

var randomIndex = Math.floor(Math.random() * students.length);
var randomElement = students[randomIndex];

console.log(randomElement);