diff --git a/Practice_Code.html b/Practice_Code.html new file mode 100644 index 0000000..4501a1a --- /dev/null +++ b/Practice_Code.html @@ -0,0 +1,13 @@ + + + + + Practice Code + + + + + + + + diff --git a/conditional.html b/conditional.html new file mode 100644 index 0000000..49f34eb --- /dev/null +++ b/conditional.html @@ -0,0 +1,10 @@ + + + + + Conditinal.html + + + + + \ No newline at end of file diff --git a/external_js.html b/external_js.html new file mode 100644 index 0000000..588ba3f --- /dev/null +++ b/external_js.html @@ -0,0 +1,10 @@ + + + + + External JS + + + + + \ No newline at end of file diff --git a/functions_js..html b/functions_js..html new file mode 100644 index 0000000..9b00ecd --- /dev/null +++ b/functions_js..html @@ -0,0 +1,11 @@ + + + + + "Welcome to Functions!" + + +

Functions Lecture

+ + + \ No newline at end of file diff --git a/inline_js.html b/inline_js.html new file mode 100644 index 0000000..d93e144 --- /dev/null +++ b/inline_js.html @@ -0,0 +1,15 @@ + + + + + Inline JS + + + console.log("Hello from Inline JavaScript."); + + + \ No newline at end of file diff --git a/js.html b/js.html new file mode 100644 index 0000000..772610c --- /dev/null +++ b/js.html @@ -0,0 +1,68 @@ + + + + + external.js + + +< + + + + + + \ No newline at end of file diff --git a/js/Practice_Code.js b/js/Practice_Code.js new file mode 100644 index 0000000..448c417 --- /dev/null +++ b/js/Practice_Code.js @@ -0,0 +1,106 @@ +"use strict"; +console.log("Practice Code Open and Running"); + +console.log("Hello from Practice Code JS!"); +var myStr =45; +// only numbers work in var, no symbols or letters. Show up as undefined. + +console.log(myStr) +// console.log will return whatever you type in in quotes as well as any input or stated var or defined item + +var howmanyPets =2; +console.log(howmanyPets) + +alert("Wow, this is nice when you know what your doing!"); +alert("Do you feel like your understand alerts and how they work?"); + +var userconfirm = confirm("Do you want to remain logged on?"); +// useconfirm = confirm -Requires input from user in form of clicking cancel or ok. +// Both alert and userconfirm remove from screen once an action is taken in box. + +alert ("The user selected: " + userconfirm) +// // By adding concatenation(+) to alert and enetring input in this case userconfirm you get a true statement. Boolean -True / False + +// var userLunch = prompt("What did you have for lunch today?") +// // prompt is always proceeded by a var "name" and can be followed up with alert "comments" and + var "name" input +// alert("The user had " + userLunch + " for lunch!") +function sayHello(name) { + return "Hello, " + name; +// // all functions must be in format shown with () and {} need a return statement +} + console.log(sayHello("codeup")); + +var helloMessage = sayHello("John"); + console.log(helloMessage); + +var myName = "John Alejandro"; + console.log(sayHello(myName)) + +// in order to run or call function - you can use console.log with ( "function name ( and whatever you want it to say")) +// function myPets(name) { +// return "Their names are, " + name; +// } +// // console.log(myPets("Bandit and Coco Chanel")); +// +// function favMovie(name) { +// return "My favorite movie is, " + name; +// } +// console.log(favMovie("The Big Blue")); +// // console.log must be outside {} of function brackets in order to work. +// +// function keepTrying(name) { +// return "Do not give up," + name; +// } +// console.log(keepTrying(" it will get better.")); +// // console.log must be outside {} of function brackets in order to work. +// +// function color(name) { +// return "My favorite color is, " + name; +// } +// console.log(color( "red.")); +// // console.log must be outside {} of function brackets in order to work. +// +// function underStand(name) { +// return "Are you starting to understand, " + name; +// } +// console.log(underStand("functions?")); +// // console.log must be outside {} of function brackets in order to work. +// +// function oneMore(name) { +// return "Keep it up don't give up on understanding, " + name; +// } +// console.log(oneMore("functions.")); +// // console.log must be outside {} of function brackets in order to work. +// +// function noMistakes(name) { +// return "You almost got it with out any " + name; +// } +// console.log(noMistakes("mistakes.")); +// // console.log must be outside {} of function brackets in order to work. + +var random = Math.floor((Math.random() * 3) + 1); + + function isTwo(number) { + console.log("Our number is: " + number); + return number === 2; +} + // console.log(isTwo(random)); +// console.log inside function {} calls function and in this case the return is a boolean value second console.log calls function with input + +// function calculateTip(tipPercentage,total){ +// return tipPercentage * total; +// } +// console.log(calculateTip(.2,20)); +// console.log(calculateTip(.5,50)); +// console.log(calculateTip(.35,20)); +// +// var userBill = prompt("How much was your Bill?"); +// var userTip = prompt("How much would you like to tip in a whole number?") / 100; +// // userTip = userTip / 100; +// alert("Thank you so much for your patronage - You will be tipping : $" + calculateTip(userTip,userBill)); + +function applyDiscount(originalPrice,discountpercent){ + return originalPrice -(originalPrice * discountpercent); +} +// function isArray(input) { +// return Array == 0;} diff --git a/js/break_and_continue.js b/js/break_and_continue.js new file mode 100644 index 0000000..7547da2 --- /dev/null +++ b/js/break_and_continue.js @@ -0,0 +1,8 @@ +console.log("Break_and_Continue.js is in the \"House\".") + + + + var prompt ("Pick an odd number between 1 and 50?"); + + + diff --git a/js/conditional.js b/js/conditional.js new file mode 100644 index 0000000..67c5947 --- /dev/null +++ b/js/conditional.js @@ -0,0 +1,132 @@ +"use strict"; + +/* ########################################################################## */ +console.log("It's working") +/** + * TODO: + * Create a function named `analyzeColor` that accepts a string that is a color + * name as input. This function should return a message that related to that + * color. Only worry about the colors defined below, if the color passed is not + * one of the ones defined below, return a message that says so + * + * Example: + * > analyzeColor('blue') // returns "blue is the color of the sky" + * > analyzeColor('red') // returns "Strawberries are red" + * > analyzeColor('cyan') // returns "I don't know anything about cyan" + * + * You should use an if-else-if-else block to return different messages. + * + * Test your function by passing various string literals to it and + * console.logging the function's return value + */ +function analyzeColor(input) { + if (input === "blue") { + alert("The ocean appears blue.") + } else if (input === "red") { + alert("Your garden roses are a vivid red.") + } else { + alert("I'm not sure what color that is.") + + } +} +console.log("The function analyzeColor returns value."); +// Don't change the next two lines! +// These lines create two variables for you: +// - `colors`: a list of the colors of the rainbow +// - `randomColor`: contains a single random color value from the list (this +// will contain a different color every time the page loads) +var colors = ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet']; +var randomColor = colors[Math.floor(Math.random() * colors.length)]; +/** + * TODO: + * Pass the `randomColor` variable to your function and console.log the results. + * You should see a different message every time you refresh the page + */ +function analyzeColor(input) { + if (input === "blue") { + alert("The ocean appears blue.") + } else if (input === "red") { + alert("Your garden roses are a vivid red.") + } else { + alert("I'm not sure what color that is.") + + } +} +console.log("The function analyzeColor returns different values."); +/** + * TODO: + * Refactor your above function to use a switch-case statement + */ +switch (analyzeColor) { + case "blue": + alert("The ocean appears blue."); + break; + case "red": + alert("Your garden roses are a vivid red."); + break; + default: + alert("I'm not sure what color that is."); + break; +} +console.log("Switch-case is working"); +/** + * + * TODO: + * Prompt the user for a color when the page loads, and pass the input from the + * user to your `analyzeColor` function. Alert the return value from your + * function to show it to the user. + */ +var analyzeColor = prompt("Pick a color?"); +alert("You picked, " + analyzeColor + " that's a nice color."); +/* ########################################################################## */ + +/** + * TODO: + * Suppose there's a promotion in Walmart, each customer is given a randomly + * generated "lucky number" between 0 and 5. If your lucky number is 0 you have + * no discount, if your lucky number is 1 you'll get a 10% discount, if it's 2, + * the discount is 25%, if it's 3, 35%, if it's 4, 50%, and if it's 5 you'll get + * all for free!. + * + * Write a function named `calculateTotal` that accepts a lucky number and total + * amount, and returns the discounted price. + * + * Example: + * calculateTotal(0, 100) // returns 100 + * calculateTotal(4, 100) // returns 50 + * calculateTotal(5, 100) // returns 0 + * + * Test your function by passing it various values and checking for the expected + * return value. + */ +function calculateTotal(totalAmount,luckyDiscount) { + return totalAmount-(totalAmount * luckyDiscount); + +} + +/** + * TODO: + * Uncomment the line below to generate a random number between 0 and 6. + * Prompt the user for their total bill, then use your `calculateTotal` function + * and alerts to display to the user what their lucky number was, what their + * price before the discount was, and what their price after the discount is. + */ +// Generate a random number between 0 and 6 +// var luckyNumber = Math.floor(Math.random() * 6); + +/** + * TODO: + * Write some JavaScript that uses a `confirm` dialog to ask the user if they + * would like to enter a number. If they click 'Ok', prompt the user for a + * number, then use 3 separate alerts to tell the user: + * + * - whether the number is even or odd + * - what the number plus 100 is + * - if the number is negative or positive + * + * if what the user enters is not a number, use an alert to tell them that, and + * do *not* display any of the above information. + * + * Can you refactor your code to use functions? + * HINT: The way we prompt for a value could be improved + */ \ No newline at end of file diff --git a/js/for_loops.js b/js/for_loops.js new file mode 100644 index 0000000..2a77379 --- /dev/null +++ b/js/for_loops.js @@ -0,0 +1,36 @@ +console.log("Yup, \"fruit\" for_loops.js is up and running.") + +function showMultiplicationTable(x) { + for ( var i = 1; i <= 10; i++) { + console.log( x + " x " + i + " = " + i*x) ; + } +}showMultiplicationTable(7) +function oddEvenRandomNumber() { + for ( var i = 19; i <200; i++) { + if ( i % 3 === 0) + console.log(i + " is odd."); + else if (i % 2 === 0) + console.log(i + " is even."); + } +} +oddEvenRandomNumber() + +function numberPyramid() { + for ( var i = 1; i <= 9; i++) { + var number = ""; + for ( var j =1; j <= i; j++) { + number = number + i.toString() + } + console.log(number); + + } +} + +numberPyramid() + +function countDown() { + for (var i = 100; i >= 5; i=i-5 ) + console.log (i) +} + +// countDown() \ No newline at end of file diff --git a/js/functions.js b/js/functions.js new file mode 100644 index 0000000..1c2e5f0 --- /dev/null +++ b/js/functions.js @@ -0,0 +1,102 @@ +"use strict"; + +/** + * TODO: + * Create a function called 'sayHello' that takes a parameter 'name'. + * When called, the function should return a message that says hello to the passed in name. + + * Example + * > sayHello("codeup") // returns "Hello, codeup!" + */ +function sayHello(name) { + return "Hello, " + name; +} +/** + * TODO: + * Call the function 'sayHello' and pass your name as a string literal argument. + * Store the result of the function call in a variable named 'helloMessage'. + * + * console.log 'helloMessage' to check your work + */ +sayHello(name); + var helloMessage = "Hello, " + name; + console.log("helloMessage") +/** + * TODO: + * Store your name as a string in a variable named 'myName', and pass that + * variable to the 'sayHello' function. You should see the same output in the + * console. + */ + var myName = "John"; + console.log(sayHello(myName)) + +// Don't modify the following line, it generates a random number between 1 and 3 +// and stores it in a variable named random +var random = Math.floor((Math.random() * 3) + 1); + +/** + * TODO: + * Create a function called 'isTwo' that takes a number as a parameter. + * The function should return a boolean value based on whether or not the passed + * number is the number 2. + * + * Example + * > isTwo(1) // returns false + * > isTwo(2) // returns true + * > isTwo(3) // returns false + * + * Call the function 'isTwo' passing the variable 'random' as a argument. + * + * console.log *outside of the function* to check your work (you should see a + * different result everytime you refresh the page if you are using the random + * number) + */ +function isTwo(number) { + if (number === 2) { + return true; + } + return false; +} + console.log(isTwo(random)) +/** + * TODO: + * Create a function named 'calculateTip' to calculate a tip on a bill at a + * restaurant. The function should accept a tip percentage and the total of the + * bill, and return the amount to tip + * + * Examples: + * > calculateTip(0.20, 20) // returns 4 + * > calculateTip(0.25, 25.50) // returns 6.375 + * > calculateTip(0.15, 33.42) // returns 5.013 + */ +function calculateTip(total,tippercentage) { + return (total * tippercentage)/100; +} + console.log("calculateTip"); +/** + * TODO: + * Use prompt and alert in combination with your calculateTip function to + * prompt the user for the bill total and a percentage they would like to tip, + * then display the dollar amount they should tip + */ +var userbill = prompt("How much is the bill?") +var usertip = prompt("How much would you like to tip?") +alert("Thank you so much, here's your tip " + "$" + usertip + "."); +/** + * TODO: + * Create a function named `applyDiscount`. This function should accept a price + * (before a discount is applied), and a discount percentage (a number between 0 + * and 1). It should return the result of applying the discount to the original + * price. + * + * Example: + * > var originalPrice = 100; + * > var dicountPercent = .2; // 20% + * > applyDiscount(originalPrice, dicountPercent) // 80 + * + * > applyDiscount(45.99, 0.12) // 40.4712 + */ +function applyDiscount(originalprice,discountPercent) { + var discount = originalprice-(originalprice * discountPercent); + return discount; +} diff --git a/js/loops.js b/js/loops.js new file mode 100644 index 0000000..9352bb0 --- /dev/null +++ b/js/loops.js @@ -0,0 +1,18 @@ +console.log("Loops is working.") + +// var i = 0; +// while( i <= 30) { +// console.log("Count to " + i ); +// i++; +// } +// var i = 10; +// while ( i <= 10) { +// console.log("Count up from " + i); +// i--; +// } +// var x = 0; +// while (true) { +// if (x === 5); +// alert(" Never ending song." + x.length); +// break; +// } \ No newline at end of file diff --git a/js/while.js b/js/while.js new file mode 100644 index 0000000..e33d686 --- /dev/null +++ b/js/while.js @@ -0,0 +1 @@ +console.log("While you were waiting.") \ No newline at end of file diff --git a/loops.html b/loops.html new file mode 100644 index 0000000..602b9e6 --- /dev/null +++ b/loops.html @@ -0,0 +1,13 @@ + + + + + Loops + + + + + + + + \ No newline at end of file