diff --git a/INFO-1272 (JS 1)/Notes/Midterm/index.js b/INFO-1272 (JS 1)/Notes/Midterm/index.js index 35af291..d5b8b3e 100644 --- a/INFO-1272 (JS 1)/Notes/Midterm/index.js +++ b/INFO-1272 (JS 1)/Notes/Midterm/index.js @@ -1,51 +1,190 @@ -for (var i = 1; i < 10; i++) { - console.log("Ran " + i + " time(s).") -}; +// for (var i = 1; i < 10; i++) { +// console.log("Ran " + i + " time(s).") +// }; -console.log(window.confirm("Feel prepared?")); // true or false +// console.log(window.confirm("Feel prepared?")); // true or false -var question = ("50" === 50); -console.log(question); +// var question = ("50" === 50); +// console.log(question); -var question2 = (true && false); -console.log(question2); +// var question2 = (true && false); +// console.log(question2); -var question3 = (true || false); -console.log(question3); +// var question3 = (true || false); +// console.log(question3); -// VAR price = 35.6; <-- WRONG -var price = 35.6; // <-- RIGHT +// // VAR price = 35.6; <-- WRONG +// var price = 35.6; // <-- RIGHT -var city = "London"; +// var city = "London"; -if (city.toLowerCase() === "london") { - console.log("I live there too!"); +// if (city.toLowerCase() === "london") { +// console.log("I live there too!"); +// } else { +// console.log("I dont know where that is.") +// } + +// var userName = window.prompt("Please enter your name:"); +// greetUser(userName); + +// var radius = window.prompt("Please enter circle radius:"); +// calcCirc(radius); + +// var testNum = window.prompt("Number to test for even:"); +// isEven(testNum); + +// function greetUser(userName) { +// alert("Hello " + userName + " welcome to the page"); +// } + +// function calcCirc(radius) { +// var Circ = ((2 * Math.PI) * radius).toFixed(2); +// alert("Circumference is: " + Circ + " Inches."); +// } + +// function isEven(number) { +// if (number % 2 == 0) { +// console.log(number + " is even"); +// } else { +// console.log(number + " is odd"); +// } +// } + +// NUMBER GUESSING GAME +// var randomNum = Math.floor((Math.random() * 100) + 1); +// console.log("Random Number: " + randomNum); + +// var userGuess; +// do { +// var input = window.prompt("Guess a number from 1-100: "); +// if (input === null) { +// window.alert("Game cancelled."); +// break; +// } + +// userGuess = parseInt(input, 10); +// if (isNaN(userGuess) || userGuess < 1 || userGuess > 100) { +// window.alert("Please enter a valid number between 1 and 100."); +// } else if (userGuess !== randomNum) { +// window.alert("Incorrect number, try again!"); +// } +// } while (userGuess !== randomNum); + +// if (userGuess === randomNum) { +// window.alert("You guessed the right number! The number was " + randomNum); +// } + +// ROCK PAPER SCISSORS GAME +// var choices = ["rock", "paper", "scissors"]; +// var compChoice = choices[Math.floor(Math.random() * 3)]; +// console.log("Computer choice: " + compChoice); + +// var userChoice = window.prompt("Enter rock, paper or scissors: ").toLowerCase(); +// console.log("User choice: " + userChoice); + +// if (!choices.includes(userChoice)) { +// window.alert("Invalid choice!"); +// } else if (userChoice === compChoice) { +// window.alert("It's a tie!"); +// } else { +// var winsAgainst = { +// rock: "scissors", +// paper: "rock", +// scissors: "paper" +// }; + +// if (winsAgainst[userChoice] === compChoice) { +// window.alert("You win!"); +// } else { +// window.alert("Computer wins!"); +// } +// } + +// SAMPLE BANK ACCOUNT +// var bankBalance = 0; +// console.log("Bank balance: $" + bankBalance); + +// function getAmount(message) { +// var input = window.prompt(message); +// if (input === null) return null; +// var amount = parseInt(input, 10); +// if (isNaN(amount)) { +// window.alert("Please enter a valid number."); +// return null; +// } +// return amount; +// } + +// while (true) { +// var userChoice = window.prompt( +// "Welcome! Your bank balance is: $" + bankBalance + +// ". Would you like to (w)ithdraw, (d)eposit or (v)iew balance, or (q)uit?"); +// if (userChoice === null || userChoice.toLowerCase() === "q") break; +// userChoice = userChoice.toLowerCase(); +// console.log(userChoice); + +// if (userChoice === "w" || userChoice === "withdrawl") { +// var widthdrawlAmount = getAmount("How much would you like to widthdraw?"); +// if (widthdrawlAmount === null) continue; +// if (widthdrawlAmount > bankBalance) { +// window.alert("Not enough in balance to widthdraw, sorry!"); +// } else if (widthdrawlAmount <= 0) { +// window.alert("Cannot widthdraw negative or 0 dollars."); +// } else { +// bankBalance -= widthdrawlAmount; +// console.log("Bank balance: $" + bankBalance); +// } +// } else if (userChoice === "d" || userChoice === "deposit") { +// var depositAmount = getAmount("How much would you like to deposit?"); +// if (depositAmount === null) continue; +// if (depositAmount <= 0) { +// window.alert("Cannot deposit negative or 0 dollars."); +// } else { +// bankBalance += depositAmount; +// console.log("Bank balance: $" + bankBalance); +// } +// } else if (userChoice === "v" || userChoice === "view") { +// window.alert("Your balance is: $" + bankBalance + " dollars. Thank you for banking with us!"); +// console.log("Bank balance: $" + bankBalance); +// } else { +// window.alert("Invalid choice, please try again"); +// } +// } + +// ARRAY STATS CALCULATOR +// var stats = []; +// var sum = 0; + +// for (var i = 0; i < 50; i++) { +// var randomNum = Math.floor(Math.random() * 50); +// sum += randomNum; +// stats.push(randomNum); +// console.log(randomNum); +// } +// console.log(stats); + +// console.log("Sum of stats: " + sum); +// console.log("Average of stats: " + (sum / stats.length)); +// console.log("Min of stats: " + Math.min(...stats)); +// console.log("Max of stats: " + Math.max(...stats)); + +// PASSWORD STRENGTH CHECKER +var userPass = window.prompt("Enter a password to test: "); +var charCount, numCount, symCount; + +charCount = userPass.length; +console.log(charCount); + +numCount = (userPass.match(/\d/g) || []).length; +console.log(numCount); + +symCount = (userPass.match(/[^a-zA-Z0-9]/g) || []).length; +console.log(symCount); + +if (charCount >= 10 && numCount >= 3 && symCount >= 1) { + window.alert("Your password is STRONG"); +} else if (charCount >= 10 && numCount >= 1) { + window.alert("Your password is OKAY"); } else { - console.log("I dont know where that is.") -} - -var userName = window.prompt("Please enter your name:"); -greetUser(userName); - -var radius = window.prompt("Please enter circle radius:"); -calcCirc(radius); - -var testNum = window.prompt("Number to test for even:"); -isEven(testNum); - -function greetUser(userName) { - alert("Hello " + userName + " welcome to the page"); -} - -function calcCirc(radius) { - var Circ = ((2 * Math.PI) * radius).toFixed(2); - alert("Circumference is: " + Circ + " Inches."); -} - -function isEven(number) { - if (number % 2 == 0) { - console.log(number + " is even"); - } else { - console.log(number + " is odd"); - } + window.alert("Your password is WEAK"); } \ No newline at end of file