diff --git a/practice.js b/practice.js index 526c6202..dfe4b4e1 100644 --- a/practice.js +++ b/practice.js @@ -2,31 +2,30 @@ //Create a variable called myName that is a string data type -//Code here +var myName = "Saddam"; //////////////////PROBLEM 2//////////////////// //Create a variable called myAge that is a number data type -//Code here +var myAge=20; //////////////////PROBLEM 3//////////////////// //Create a variable called lovesCode that is a boolean data type -//Code here +var lovesCode=true; //////////////////PROBLEM 4//////////////////// //Create a variable called greatestFear that is undefined because we fear nothing -//Code here - +var greatestFear; //////////////////PROBLEM 5//////////////////// //Create a variable called devMountainGoal that is null because we are just starting out -//Code here +var devMountainGoal=null; //////////////////PROBLEM 6//////////////////// @@ -35,21 +34,27 @@ //greeting should return the string "Hello, " //plus the value of the name parameter. -//Code here +function greeting(name){ + return "Hello, "+name; +} //////////////////PROBLEM 7//////////////////// //Write a function expression called newGreeting. //Give it the same functionality as the function greeting in Problem 6. -//Code Here +var newGreeting=function (name){ + return "Hello, "+name; +} +newGreeting(); //////////////////PROBLEM 8//////////////////// //Create an array called groceries with the values //"apples", "milk", "eggs", "bread" -//Code Here +var groceries=["apples", "milk", "eggs", "bread"]; + //////////////////PROBLEM 9//////////////////// @@ -58,12 +63,17 @@ //name (a string), color (a string), age (a number), //and goodBoy (a boolean). -//Code Here +var dog={ + name:'sammy', + color:'black', + age:4, + goodBoy:true, +}; //...access the dog's name from the object and assign it to a //variable called devMountainClassPet. -//Code Here +var devMountainClassPet=dog.name; //////////////////PROBLEM 10//////////////////// @@ -74,7 +84,17 @@ // If the name parameter is anything else, return 'Cool name, NAMEPARAM' // with NAMEPARAM being the name parameter being passed in (not literally NAMEPARAM) -// Code here +function nameCheck(name){ + if(name=="Steven"){ + return "What is up Steven?"; + } + else if (name=="Bryan") + { + return "Hey Bryan!"; + } else { + return "Cool name, "+name; + } +} //////////////////PROBLEM 11//////////////////// @@ -82,12 +102,15 @@ // that will be numbers. // The add function should return the two parameters added together -//Code Here +function add(n1,n2){ + return n1+n2; +} //Now invoke add, passing in the numbers 3 and 4 //storing the result in the variable mathSum. -//Code Here +mathSum=add(3,4); + //////////////////PROBLEM 12//////////////////// @@ -98,7 +121,20 @@ // If the passed in color equals 'black', return 'so trendy' // Otherwise, you should return the string 'you need to evaluate your favorite color choice' -// Code here +function faveColorFinder(color){ + if(color=="red"){ + return 'red is a great color'; + } + else if(color=="green"){ + return 'green is a solid favorite color'; + } + else if(color=="black"){ + return'so trendy'; + } + else{ + return 'you need to evaluate your favorite color choice'; + } +} //////////////////PROBLEM 13//////////////////// @@ -122,28 +158,26 @@ function pond() { //as strings. //This array should contain the variable names (as strings) accessible in the global scope. -let globalScope = ["duck", "sailorDuck", "rubberDuck", "realDuck"]; +let globalScope = ["duck"]; //This array should contain the variable names (as strings) accessible in the bathroom function. -let bathroomScope = ["duck", "sailorDuck", "rubberDuck", "realDuck"]; +var bathroomScope = ["duck","rubberDuck"]; //This array should contain the variable names (as strings) accessible in the bathtub function. -let bathtubScope = ["duck", "sailorDuck", "rubberDuck", "realDuck"]; +var bathtubScope = ["duck","rubberDuck","sailorDuck"]; //This array should contain the variable names (as strings) accessible in the pond function. -let pondScope = ["duck", "sailorDuck", "rubberDuck", "realDuck"]; +var pondScope = ["duck","realDuck"]; //////////////////PROBLEM 14//////////////////// //Create a variable called age with your age assigned to you -// Code Here +var age=20; // FLASH FORWARD TO NEXT YEAR // reassign the value of age to be one greater than it was, because, we all get older - -// Code Here +age++ // Good news! We can live forever. Set your age to 999 - -// Code Here +age=999; \ No newline at end of file