From d3b0e3347c03d045cf9aca1fa55da7e84023a445 Mon Sep 17 00:00:00 2001 From: Fitsumhelina Date: Sat, 30 Nov 2024 21:51:29 +0300 Subject: [PATCH] exercise one and two complated --- Exercises/day-1/class-Exercise.js | 66 +++++++++++++++++++++++++++++++ Exercises/test/test.js | 47 ++++++++++++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 Exercises/day-1/class-Exercise.js diff --git a/Exercises/day-1/class-Exercise.js b/Exercises/day-1/class-Exercise.js new file mode 100644 index 0000000..b59c07f --- /dev/null +++ b/Exercises/day-1/class-Exercise.js @@ -0,0 +1,66 @@ +// Exercises Level 1 +// Create an Animal class. The class will have name, age, color, legs properties and create different methods +class animal{ + constructor (name, age, color, legs){ + this.name = name + this.age = age + this.color = color + this.legs = legs + } +} + +// Create a Dog and Cat child class from the Animal Class. +class dog extends { + constructor (name, age, color, legs){ + super(name, age, color, legs) + this.sound = 'woofff' + } +}, +class cat extends { + constructor (name, age, color, legs){ + super(name, age, color, legs) + this.sound = 'meow' + } +} + +// Exercises Level 2 +// Override the method you create in Animal class + +// > done in the above + +// Exercises Level 3 +// Let's try to develop a program which calculate measure of central tendency of a sample(mean, median, mode) +// and measure of variability(range, variance, standard deviation). In addition to those measures find the min, max, count, percentile, +// and frequency distribution of the sample. You can create a class called Statistics and create all the functions which do statistical +// calculations as method for the Statistics class. Check the output below. + + +// ages = [31, 26, 34, 37, 27, 26, 32, 32, 26, 27, 27, 24, 32, 33, 27, 25, 26, 38, 37, 31, 34, 24, 33, 29, 26] + +// console.log('Count:', statistics.count()) // 25 +// console.log('Sum: ', statistics.sum()) // 744 +// console.log('Min: ', statistics.min()) // 24 +// console.log('Max: ', statistics.max()) // 38 +// console.log('Range: ', statistics.range() // 14 +// console.log('Mean: ', statistics.mean()) // 30 +// console.log('Median: ',statistics.median()) // 29 +// console.log('Mode: ', statistics.mode()) // {'mode': 26, 'count': 5} +// console.log('Variance: ',statistics.var()) // 17.5 +// console.log('Standard Deviation: ', statistics.std()) // 4.2 +// console.log('Variance: ',statistics.var()) // 17.5 +// console.log('Frequency Distribution: ',statistics.freqDist()) // [(20.0, 26), (16.0, 27), (12.0, 32), (8.0, 37), (8.0, 34), (8.0, 33), (8.0, 31), (8.0, 24), (4.0, 38), (4.0, 29), (4.0, 25)] + +// console.log(statistics.describe()) +// // you output should look like this + +// Count: 25 +// Sum: 744 +// Min: 24 +// Max: 38 +// Range: 14 +// Mean: 30 +// Median: 29 +// Mode: (26, 5) +// Variance: 17.5 +// Standard Deviation: 4.2 +// Frequency Distribution: [(20.0, 26), (16.0, 27), (12.0, 32), (8.0, 37), (8.0, 34), (8.0, 33), (8.0, 31), (8.0, 24), (4.0, 38), (4.0, 29), (4.0, 25)] \ No newline at end of file diff --git a/Exercises/test/test.js b/Exercises/test/test.js index 157aa29..7560f99 100644 --- a/Exercises/test/test.js +++ b/Exercises/test/test.js @@ -42,3 +42,50 @@ // const value = numbers.reduce((acc, cur) => acc * cur ,0) // console.log(value) // 0 + +class Person { + constructor (firstName, lastName, age, country, city, score = 0, skills = []) { + this.firstName = firstName + this.lastName = lastName + this.age = age + this.country = country + this.city = city + this.score = score + this.skills = skills + } + + getFullName() { + const fullName = this.firstName + ' ' + this.lastName + return fullName + } +} + +// const person1 = new Person('Asabeneh', 'Yetayeh', 250, 'Finland', 'Helsinki', 13, ['html', 'css', 'js', 'react']); +// const person2 = new Person('Lidiya', 'Tekle', 28, 'Finland', 'Espoo', 0, ['html']); // Corrected skills + +// console.log(person1.city); // Helsinki +// console.log(person1.skills); // ['html', 'css', 'js', 'react'] +// console.log(person2.city); // Espoo +// console.log(person2.skills); + +// const showDateTime = () => { +// let now = new Date() +// let year = now.getFullYear() +// let month = now.getMonth() + 1 +// let date = now.getDate() +// let hours = now.getHours() +// let minutes = now.getMinutes() +// if (hours < 10) { +// hours = '0' + hours +// } +// else if (hours > 12) { +// hours -=12 +// } + +// let datee = `${year}/${month}/${date}` +// let Time = `${hours}:${minutes}` +// return datee + "," + Time +// } + +// console.log(showDateTime()) // 2019/10/12 12:46 +