├── Build a Library ├── Readme └── script.js ├── Dog Years ├── README └── index.js ├── Dragon Slayer ├── Readme └── script.js ├── Kelvin WEather-prompt ├── KelvinWeather(prompt).js └── README ├── KelvinWeather ├── KelvinWeather.js └── README ├── Magic Eight Ball ├── README └── script.js ├── Meal Maker ├── Readme └── script.js ├── Password Validator ├── readme └── script.js ├── README.md ├── Race Day ├── README └── script.js ├── Rock-Paper-Scissors ├── Readme └── script.js ├── School Catalogue ├── readme └── script.js ├── Sleep Debt Calculator ├── readme └── script.js ├── Training Days ├── readme └── script.js └── Whale Talk ├── Readme └── script.js /Build a Library/Readme: -------------------------------------------------------------------------------- 1 | Using classes to create a library system in JavaScript. 2 | -------------------------------------------------------------------------------- /Build a Library/script.js: -------------------------------------------------------------------------------- 1 | //creating a parent class Media 2 | class Media{ 3 | constructor(title){ 4 | this._title = title; 5 | this._isCheckedOut = false; 6 | this._ratings = []; 7 | } 8 | //creating a getters for tittle, isCheckedOut and ratings 9 | get title(){ 10 | return this._title; 11 | } 12 | 13 | get isCheckedOut(){ 14 | return this._isCheckedOut; 15 | } 16 | 17 | get ratings(){ 18 | return this._ratings; 19 | } 20 | //creating a method toggleCheckOutStatus that changes the valuse saved to the _isCheckedOut property 21 | toggleCheckOutStatus(){ 22 | this._isCheckedOut = !this._isCheckedOut; 23 | } 24 | 25 | //creating a method getAverageRating that returns an average value of ratings array 26 | getAverageRating(){ 27 | let ratingsSum = this.ratings.reduce((currentSum, rating) => currentSum + rating, 0)/this._ratings.length; 28 | return ratingsSum; 29 | } 30 | 31 | //creating a method addRating 32 | addRating(ratings){ 33 | this._ratings.push(ratings); 34 | } 35 | } 36 | 37 | //creating a Book class that extends Media/parent class 38 | class Book extends Media { 39 | constructor(author, title, pages){ 40 | super(title); 41 | this._author = author; 42 | this._pages = pages; 43 | } 44 | 45 | 46 | //creating a getters for author and pages 47 | get author(){ 48 | return this._author; 49 | } 50 | 51 | get pages(){ 52 | return this._pages; 53 | } 54 | } 55 | 56 | //creating a Movie class that extends Media/parent class 57 | class Movie extends Media{ 58 | constructor(director, title, runTime){ 59 | super(title); 60 | this._director = director; 61 | this._runTime = runTime; 62 | } 63 | 64 | //creating a getters for director and runTime 65 | get director(){ 66 | return this._director; 67 | } 68 | 69 | get runTime(){ 70 | return this._runTime; 71 | } 72 | } 73 | 74 | //creating a Book instance with the following properties 75 | const historyOfEverything = new Book('Bill Bryson', 'A Short History of Nearly Everything', 544); 76 | 77 | //calling .toggleCheckOutStatus() on the historyOfEverything instance 78 | historyOfEverything.toggleCheckOutStatus(); 79 | 80 | //log the value 81 | console.log(historyOfEverything.isCheckedOut); 82 | 83 | //call .addRating 84 | historyOfEverything.addRating(4); 85 | historyOfEverything.addRating(5); 86 | historyOfEverything.addRating(5); 87 | historyOfEverything.getAverageRating(); 88 | 89 | //log the result 90 | console.log(historyOfEverything.getAverageRating()); 91 | 92 | 93 | //creating a Movie instance with the following properties 94 | const speed = new Movie('Jan de Bont', 'Speed', 116); 95 | 96 | //Call .toggleCheckOutStatus() on the speed instance. 97 | speed.toggleCheckOutStatus(); 98 | 99 | //log the value 100 | console.log(speed.isCheckedOut); 101 | 102 | //call .addRating 103 | speed.addRating(1); 104 | speed.addRating(1); 105 | speed.addRating(5); 106 | speed.getAverageRating(); 107 | 108 | //log the result 109 | console.log(speed.getAverageRating()); 110 | 111 | console.log(historyOfEverything); 112 | console.log(speed); 113 | -------------------------------------------------------------------------------- /Dog Years/README: -------------------------------------------------------------------------------- 1 | using JavaScript to convert my age into dog years 2 | -------------------------------------------------------------------------------- /Dog Years/index.js: -------------------------------------------------------------------------------- 1 | var myAge = 20; 2 | var firstYears = 2 * 10.5; 3 | var laterYears = (myAge - 2) * 4; 4 | var myAgeInDogYears = firstYears + laterYears; 5 | console.log('My age in dog years is ' +myAgeInDogYears + '.'); 6 | -------------------------------------------------------------------------------- /Dragon Slayer/Readme: -------------------------------------------------------------------------------- 1 | In this game, you’ll battle a dragon. It will take 4 hits to slay the dragon, and if you miss even one hit, the dragon will defeat you! 2 | from: https://b0nez.github.io/Codecademy/4.1%20-%20Dragon%20Slayer!.html 3 | -------------------------------------------------------------------------------- /Dragon Slayer/script.js: -------------------------------------------------------------------------------- 1 | var slaying = true; 2 | var youHit = Math.floor(Math.random() * 2); 3 | var damageThisRound = Math.floor(Math.random() * 5 + 1); 4 | var totalDamage = 0; 5 | 6 | while (slaying) { 7 | if (youHit) { 8 | console.log("You hit the dragon and did " + damageThisRound + " damage!"); 9 | totalDamage += damageThisRound; 10 | 11 | if (totalDamage >= 4) { 12 | console.log("You did it! You slew the dragon!"); 13 | slaying = false; 14 | } else { 15 | youHit = Math.floor(Math.random() * 2); 16 | } 17 | } else { 18 | console.log("The dragon burninates you! You're toast."); 19 | slaying = false; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Kelvin WEather-prompt/KelvinWeather(prompt).js: -------------------------------------------------------------------------------- 1 | const kelvin = prompt('What is the Kelvin temperature today?'); 2 | /*const kelvin = 294;*/ 3 | const celsius = kelvin - 273; 4 | let fahrenheit = celsius * (9/5) + 32; 5 | fahrenheit = Math.floor(fahrenheit); 6 | console.log(`The temperature is ${fahrenheit} degrees fahrenheit.`); 7 | -------------------------------------------------------------------------------- /Kelvin WEather-prompt/README: -------------------------------------------------------------------------------- 1 | Using JavaScript to turn a weather forecast in Kelvin, to Fahrenheit. 2 | -------------------------------------------------------------------------------- /KelvinWeather/KelvinWeather.js: -------------------------------------------------------------------------------- 1 | var kelvin = 293; 2 | var celsius = kelvin - 273; 3 | var fahrenheit = celsius * (9/5) + 32; 4 | console.log('The temperature is ' + fahrenheit + ' fahrenheit.'); 5 | -------------------------------------------------------------------------------- /KelvinWeather/README: -------------------------------------------------------------------------------- 1 | project from Codecademy/JavaScript: changing Kelvin Weather to fahrenheit 2 | -------------------------------------------------------------------------------- /Magic Eight Ball/README: -------------------------------------------------------------------------------- 1 | Creating a JavaScript Magic Eight Ball to predict your future ;) 2 | -------------------------------------------------------------------------------- /Magic Eight Ball/script.js: -------------------------------------------------------------------------------- 1 | let userName = 'Ela'; 2 | 3 | userName ? console.log(`Hello, ${userName}.`) : console.log('Hello!'); 4 | 5 | let userQuestion = 'Will I do this exercise?'; 6 | let randomNumber = Math.floor(Math.random() * 7); 7 | let eightBall = ''; 8 | 9 | switch (randomNumber){ 10 | case 0: 11 | eigthBall = 'It is certain'; 12 | break; 13 | case 1: 14 | eightBall = 'It is decidedly so'; 15 | break; 16 | case 2: 17 | eightBall = 'Reply hazy try again'; 18 | break; 19 | case 3: 20 | eightBall = 'Cannot predict now'; 21 | break; 22 | case 4: 23 | eightBall = 'Dont count on it'; 24 | break; 25 | case 5: 26 | eightBall = 'My sources say no'; 27 | break; 28 | case 6: 29 | eightBall = 'Outlook not so good'; 30 | break; 31 | case 7: 32 | eightBall = 'Signs point to yes'; 33 | break; 34 | } 35 | 36 | console.log('User question: ' + userQuestion); 37 | console.log('The eight ball answer: ' + eightBall); 38 | -------------------------------------------------------------------------------- /Meal Maker/Readme: -------------------------------------------------------------------------------- 1 | Making a program using JavaScript that creates a new three-course meal given a restaurant's menu. 2 | -------------------------------------------------------------------------------- /Meal Maker/script.js: -------------------------------------------------------------------------------- 1 | const menu = { 2 | //This property will ultimately contain a mapping between each course and the dishes available to order in that course 3 | _courses: { 4 | _appetizers: [], 5 | _mains: [], 6 | _desserts: [], 7 | 8 | //Creating getter and setter methods for the appetizers, mains, and desserts properties. 9 | get appetizers() { 10 | return this._appetizers; 11 | }, 12 | set appetizers(appetizersIn) { 13 | this._appetizers = appetizersIn; 14 | }, 15 | get mains() { 16 | return this._mains 17 | }, 18 | set mains(mainsIn) { 19 | this._mains = mainsIn; 20 | }, 21 | get desserts() { 22 | return this._desserts; 23 | }, 24 | set desserts(dessertsIn) { 25 | this._desserts = dessertsIn; 26 | }, 27 | }, 28 | 29 | //creating an empty getter method for the _courses property. 30 | get courses() { 31 | return { 32 | appetizers: this._courses.appetizers, 33 | mains: this._courses.mains, 34 | desserts: this._courses.desserts, 35 | }; 36 | }, 37 | 38 | 39 | //creating a method called .addDishToCourse() which will be used to add a new dish to the specified course on the menu. 40 | addDishToCourse(courseName, dishName, dishPrice) { 41 | const dish = { 42 | name: dishName, 43 | price: dishPrice, 44 | }; 45 | 46 | this._courses[courseName].push(dish); 47 | }, 48 | 49 | //function which will allow us to get a random dish from a course on the menu, which will be necessary for generating a random meal 50 | getRandomDishFromCourse(courseName) { 51 | const dishes = this._courses[courseName]; 52 | const randomIndex = Math.floor(Math.random() * dishes.length); 53 | return dishes[randomIndex]; 54 | }, 55 | 56 | //function which will automatically generate a three-course meal for us. 57 | generateRandomMeal() { 58 | const appetizer = this.getRandomDishFromCourse('appetizers'); 59 | const main = this.getRandomDishFromCourse('mains'); 60 | const dessert = this.getRandomDishFromCourse('desserts'); 61 | const totalPrice = appetizer.price + main.price + dessert.price; 62 | 63 | return `Your meal is ${appetizer.name}, ${main.name} and ${dessert.name}. The price is $${totalPrice.toFixed(2)}.`; 64 | }, 65 | }; 66 | 67 | //adding dishes to appetizers, mains and desserts 68 | menu.addDishToCourse('appetizers', 'Ceasar Salad', 4.25); 69 | menu.addDishToCourse('appetizers', 'Chicken Salad', 3.90); 70 | menu.addDishToCourse('appetizers', 'Bruschetta', 1.99); 71 | 72 | menu.addDishToCourse('mains', 'Burger', 7.00); 73 | menu.addDishToCourse('mains', 'Steak', 10.12); 74 | menu.addDishToCourse('mains', 'Fish', 18.20); 75 | 76 | menu.addDishToCourse('desserts', 'Cake', 2.00); 77 | menu.addDishToCourse('desserts', 'Ice Cream', 1.85); 78 | menu.addDishToCourse('desserts', 'Cake 2', 2.20); 79 | 80 | //generating a meal 81 | let meal = menu.generateRandomMeal(); 82 | 83 | //printing result 84 | console.log(meal); 85 | -------------------------------------------------------------------------------- /Password Validator/readme: -------------------------------------------------------------------------------- 1 | Verify that a password is secure:) 2 | (The rules for our password validator are: 3 | 4 | Has at least one uppercase letter 5 | Has at least one lowercase letter 6 | Is at least 8 characters long 7 | Has at least one special character) 8 | -------------------------------------------------------------------------------- /Password Validator/script.js: -------------------------------------------------------------------------------- 1 | //A function that verifies the password has an uppercase letter. 2 | function hasUppercase(input){ 3 | for (var i = 0; i= 8){ 22 | return true; 23 | } 24 | } 25 | 26 | //A function that verifies the password has a special character. 27 | function hasSpecialCharacter(input){ 28 | var specialCharacters = ['!', '@', '#', '$', '%', '^', '&', '*']; 29 | 30 | for (var i = 0; i18 && earlyRegistration=== true && raceNumber <1000){ 13 | console.log(`Your race starts at 9:30 am and your race number is: ${raceNumber}`); 14 | } else if (earlyRegistration=== true || runnerAge > 18){ 15 | console.log(`Your race starts at 11:00 am and your race number is: ${raceNumber}`); 16 | } else if (runnerAge < 18 && earlyRegistration===false){ 17 | console.log(`Your race starts at 12:30 pm and your race number is: ${raceNumber}`); 18 | } else{ 19 | console.log('Please see the registration desk to get your number'); 20 | } 21 | -------------------------------------------------------------------------------- /Rock-Paper-Scissors/Readme: -------------------------------------------------------------------------------- 1 | Making use of functions and control flow to program a "Rock, Paper, Scissors" game. 2 | -------------------------------------------------------------------------------- /Rock-Paper-Scissors/script.js: -------------------------------------------------------------------------------- 1 | //getting user choice and making sure result will be in lowercase 2 | const getUserChoice = userInput =>{ 3 | userInput = userInput.toLowerCase(); 4 | 5 | //checking if user choice is 'rock', 'paper', 'scissors' or 'bomb' (which is added as an extra). 6 | //If not, there'll be an error message printed to the console 7 | if (userInput === 'rock' || userInput === 'paper' || userInput === 'scissors' || userInput === 'bomb') { 8 | return userInput; 9 | } else { 10 | console.log('Error, please type: rock, paper or scissors'); 11 | } 12 | } 13 | 14 | //computer choice 15 | const getComputerChoice = () => { 16 | let randomNumber = Math.floor(Math.random()*3); 17 | switch (randomNumber){ 18 | case 0: 19 | return 'rock'; 20 | case 1: 21 | return 'paper'; 22 | case 2: 23 | return 'scissors'; 24 | } 25 | } 26 | 27 | //checking who is a winner by comparing userChoice and computerChoice. 28 | const determineWinner = (userChoice, computerChoice)=>{ 29 | if (userChoice === computerChoice){ 30 | return "This game is a tie!"; 31 | } 32 | if (userChoice === 'rock'){ 33 | if (computerChoice === 'paper'){ 34 | return "Sorry, computer won!"; 35 | } else{ 36 | return "Congratulations, you won!"; 37 | } 38 | } 39 | if (userChoice=== 'paper'){ 40 | if(computerChoice === 'scissors'){ 41 | return 'Sorry, computer won!'; 42 | }else{ 43 | return "Congratulation, you won!"; 44 | } 45 | } 46 | 47 | if (userChoice=== 'scissors'){ 48 | if (computerChoice === 'rock'){ 49 | return 'Sorry, computer won!'; 50 | } else { 51 | return "Congratulations, you won"; 52 | } 53 | } 54 | 55 | if (userChoice==='bomb'){ 56 | return 'Congratulation, you won!'; 57 | } 58 | } 59 | 60 | //starting the game. log the results: userChoice and computer Choice 61 | const playGame = ()=>{ 62 | const userChoice = getUserChoice('paper'); 63 | const computerChoice = getComputerChoice(); 64 | console.log('You threw: ' + userChoice); 65 | console.log('The computer threw: ' + computerChoice); 66 | 67 | //who won? 68 | console.log(determineWinner(userChoice, computerChoice)); 69 | } 70 | 71 | //starting the game 72 | playGame(); 73 | -------------------------------------------------------------------------------- /School Catalogue/readme: -------------------------------------------------------------------------------- 1 | Using classes to build a catalog of schools for the Department of Education. 2 | -------------------------------------------------------------------------------- /School Catalogue/script.js: -------------------------------------------------------------------------------- 1 | class School{ 2 | constructor(name, level, numberOfStudents){ 3 | this._name = name; 4 | this._level = level; 5 | this._numberOfStudents = numberOfStudents; 6 | } 7 | get name(){ 8 | return this._name; 9 | } 10 | 11 | get level(){ 12 | return this._level; 13 | } 14 | 15 | get numberOfStudents(){ 16 | return this._numberOfStudents; 17 | } 18 | 19 | set numberOfstudents(newNumberOfStudents){ 20 | if (typeof newNumberOfStudents === 'number'){ 21 | this._numberOfstudents = newNumberOfStudents; 22 | } 23 | else { 24 | console.log('Invalid input: numberOfStudents must be set to a Number.'); 25 | return 'Invalid input: numberOfStudents must be set to a Number.'; 26 | } 27 | } 28 | 29 | quickFacts(){ 30 | console.log(`${this.name} educates ${this.numberOfStudents}, typically between the ages of ${this.level}.`); 31 | } 32 | 33 | static pickSubstituteTeacher(substituteTeachers){ 34 | let randomTeacher = Math.floor(substituteTeachers.length * Math.random() - 1); 35 | return substituteTeachers[randomTeacher]; 36 | } 37 | } 38 | 39 | class PrimarySchool extends School{ 40 | constructor(name, numberOfStudents, pickupPolicy){ 41 | super(name, 'primary', numberOfStudents); 42 | this._pickupPolicy = pickupPolicy; 43 | } 44 | 45 | get pickupPolicy(){ 46 | return this._pickupPolicy; 47 | } 48 | } 49 | 50 | class HighSchool extends School{ 51 | constructor(name, numberOfStudents, sportsTeams){ 52 | super(name, 'high', numberOfStudents); 53 | this._sportsTeams = sportsTeams; 54 | } 55 | 56 | get sportsTeams(){ 57 | return this._sportsTeams; 58 | } 59 | } 60 | 61 | console.log(HighSchool.sportsTeams); 62 | 63 | const lorraineHansbury = new PrimarySchool('Lorraine Hansbury', 514, 'Students must be picked up by a parent, guardian, or a family member over the age of 13.'); 64 | 65 | lorraineHansbury.quickFacts(); 66 | School.pickSubstituteTeacher(['Jamal Crawford', 'Lou Williams', 'J. R. Smith', 'James Harden', 'Jason Terry', 'Manu Ginobli']); 67 | 68 | 69 | const alSmith = new HighSchool('Al E. Smith', 415, ['Baseball', 'Basketball', 'Volleyball', 'Track and Field']); 70 | 71 | console.log(alSmith.sportsTeams); 72 | -------------------------------------------------------------------------------- /Sleep Debt Calculator/readme: -------------------------------------------------------------------------------- 1 | Calculate if you're getting enough sleep each week ;) 2 | -------------------------------------------------------------------------------- /Sleep Debt Calculator/script.js: -------------------------------------------------------------------------------- 1 | //checking how many hours of sleep user got each night of the week 2 | const getSleepHours = day => { 3 | switch(day){ 4 | case 'Monday': 5 | return 8; 6 | case 'Tuesday': 7 | return 7; 8 | case 'Wednesday': 9 | return 8; 10 | case 'Thursday': 11 | return 9; 12 | case 'Friday': 13 | return 6; 14 | case 'Saturday': 15 | return 10; 16 | case 'Sunday': 17 | return 8; 18 | } 19 | }; 20 | 21 | //getting total sleep hours that user actually slept for whole week 22 | const getActualSleepHours = () =>{ 23 | return getSleepHours('Monday') + 24 | getSleepHours('Tuesday') + 25 | getSleepHours('Wednesday') + 26 | getSleepHours('Thursday') + 27 | getSleepHours('Friday') + 28 | getSleepHours('Saturday') + 29 | getSleepHours('Sunday'); 30 | } 31 | 32 | //getting ideal sleep hours per day that user prefers, multiplying them by 7 as we need to count all days 33 | const getIdealSleepHours = () =>{ 34 | let idealHours = 8; 35 | return idealHours*7; 36 | } 37 | 38 | //calculating sleep debt 39 | const calculateSleepDebt = () =>{ 40 | let actualSleepHours = getActualSleepHours(); 41 | let idealSleepHours = getIdealSleepHours(); 42 | 43 | //output the result to the user, with hours, by comparing actualSleepHours and idealSleepHours 44 | if(actualSleepHours === idealSleepHours){ 45 | console.log('You have got ' + actualSleepHours + ' hours of sleep this week, it is a perfect amount.'); 46 | } 47 | if(actualSleepHours > idealSleepHours){ 48 | console.log('You got ' + (actualSleepHours - idealSleepHours) + ' hours more sleep than you needed this week.'); 49 | } 50 | if(actualSleepHours< idealSleepHours){ 51 | console.log('You got ' + (idealSleepHours - actualSleepHours) + ' hours less sleep than you needed this week. Get some rest.'); 52 | } 53 | } 54 | 55 | //start the program 56 | calculateSleepDebt(); 57 | -------------------------------------------------------------------------------- /Training Days/readme: -------------------------------------------------------------------------------- 1 | Creating a messaging program for an athletic event service. 2 | Main goal of this project was to remove variables from the global scope and create them in the block scope, demonstrating how block level variables work along the way 3 | -------------------------------------------------------------------------------- /Training Days/script.js: -------------------------------------------------------------------------------- 1 | //declaring types of events 2 | const getAllEvents = () => { 3 | return ['Marathon', 'Triathlon', 'Decathlon']; 4 | } 5 | 6 | 7 | //selects an event at random from an array of events 8 | const getRandomEvent = () => { 9 | const allEvents = getAllEvents(); 10 | const event = 11 | allEvents[Math.floor(Math.random() * allEvents.length)]; 12 | return event; 13 | }; 14 | 15 | //returns a list of the activities, based on the event selected 16 | const getEventActivities = event => { 17 | const allEvents = getAllEvents(); 18 | event= 19 | allEvents['Marathon', 'Triathlon', 'Decathlon']; 20 | 21 | if (!allEvents.includes(event)) { 22 | return null; 23 | } 24 | 25 | let activities; 26 | if (event === 'Marathon') { 27 | activities = ['Running']; 28 | } 29 | if (event === 'Triathlon') { 30 | activities = ['Running', 'Cycling', 'Swimming']; 31 | } 32 | if (event === 'Decathlon') { 33 | activities = ['Running', 'Hurdles', 'Javelin throw', 'Discus Throw', 'Shot put', 'High Jump']; 34 | } 35 | return activities.join(', ') 36 | }; 37 | 38 | //returns the number of days to train, based on the event selected 39 | const getDaysToTrain = event => { 40 | const allEvents = getAllEvents(); 41 | if (!allEvents.includes(event)) { 42 | return null; 43 | } 44 | const eventTrainingTimes = {'Marathon': 50, 'Triathlon': 100, 'Decathlon': 200 }; 45 | return eventTrainingTimes[event]; 46 | }; 47 | 48 | //calling the program 49 | const getEventMessage = ()=>{ 50 | const myEvent = getRandomEvent(); 51 | 52 | console.log('Your event is a ' + myEvent + '. Your event activities consist of ' + getEventActivities(myEvent) + '. You have ' + getDaysToTrain(myEvent) + ' days to train.'); 53 | } 54 | 55 | 56 | //starting program 57 | getEventMessage(); 58 | -------------------------------------------------------------------------------- /Whale Talk/Readme: -------------------------------------------------------------------------------- 1 | Turn any sentence into whale talk! :) 2 | -------------------------------------------------------------------------------- /Whale Talk/script.js: -------------------------------------------------------------------------------- 1 | //text that we will translate into whale language 2 | let input = 'Turpentine and turtles'; 3 | //an array of vowels that we are going to look for in input 4 | let vowels = ['u', 'e', 'i', 'a']; 5 | //array where we will store vowels that we will find 6 | let resultArray = []; 7 | 8 | //logic that compares the input variable's text to the vowels array. The goal is to find all the vowels in the input string. 9 | for (let inputIndex = 0; inputIndex< input.length; inputIndex++){ 10 | 11 | for (let vowelsIndex=0; vowelsIndex