Created
December 4, 2022 23:41
-
-
Save ivmos/16c4c29f5621999245cfb297c0e06683 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Define a class for video game consoles | |
class Console { | |
constructor(name, generation, graphics, sound, performance, catalog, aladdin, sonic) { | |
this.name = name; | |
this.generation = generation; | |
this.graphics = graphics; | |
this.sound = sound; | |
this.performance = performance; | |
this.catalog = catalog; | |
this.aladdin = aladdin; | |
this.sonic = sonic; | |
} | |
// Calculate the overall score for a console | |
score() { | |
return this.graphics * 0.15 + this.sound * 0.15 + this.performance * 0.15 + this.catalog * 0.15 + this.aladdin * 0.2 + this.sonic * 0.2; | |
} | |
} | |
// Define an array of video game consoles | |
const consoles = [ | |
new Console("Atari 2600", 2, 4, 3, 3, 4, 2, 0), | |
new Console("Sega Master System", 3, 5, 4, 4, 5, 3, 1), | |
new Console("NES", 3, 5, 4, 4, 5, 4, 0), | |
new Console("Sega Genesis", 4, 6, 5, 5, 6, 5, 1), | |
new Console("SNES", 4, 6, 5, 5, 6, 6, 0), | |
new Console("PlayStation 1", 5, 7, 6, 6, 7, 7, 0), | |
new Console("Sega Saturn", 5, 7, 6, 6, 7, 8, 1), | |
new Console("PlayStation 2", 6, 8, 7, 7, 8, 9, 0) | |
]; | |
// Compare the consoles and print their scores | |
for (const console of consoles) { | |
console.log(`${console.name}: ${console.score()}`); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment