Hello, I have written my random bear generator but for some reason the code isn't running in my command terminal. Please have a look at it and let me know what I am missing. I followed my teachers instructors and lectures, but it doesn't run on another compiler either. class Bear {   constructor(type, color, weight, favoriteFood) {     this.type = type;     this.color = color;     this.weight = weight;     this.favoriteFood = favoriteFood;     if (this.weight === 700 || this.type === "Little Bear" || this.type === "Baby Bear") {       this.isAggressive = false;     } else if (this.weight === 1200 || this.type === "Papa Bear" || this.type === "Black Bear") {       this.isAggressive = true;     } else {       this.isAggressive = Math.random() < 0.5;     }     if (this.type === "Winnie the Pooh Bear" && this.favoriteFood !== "Honey") {       throw new Error("Winnie the Pooh Bear must have Honey as his favorite food.");     }   } } class BearGenerator {   get types() {     return [       "Winnie the Pooh Bear",       "Yogi Bear",       "Boo-boo Bear",       "Paddington Bear",       "Mama Bear",       "Papa Bear",       "Baby Bear",       "Little Bear",       "Teddy Bear",       "Smokey Bear",     ];   }   get colors() {     return [       "Red",       "Blue",       "White",       "Indigo",       "Green",       "Teal",       "Fuchsia",       "Brown",       "Violet",       "Black",     ];   }   get foods() {     return [       "Honey",       "Pizza",       "Burger",       "Burrito",       "Wings",       "Spaghetti",       "Steak",     ];   }   createRandomBear() {     const type = this.types[Math.floor(Math.random() * this.types.length)];     const color = this.colors[Math.floor(Math.random() * this.colors.length)];     const weight = Math.floor(Math.random() * 1250) + 250;     const favoriteFood = this.foods[Math.floor(Math.random() * this.foods.length)];     return new Bear(type, color, weight, favoriteFood);   } } class DataProcessor {   constructor(data) {     this.data = data;   }   getStatsFor(valuesArray, property) {     const stats = {};     for (const value of valuesArray) {       stats[value] = 0;     }     for (const bear of this.data) {       stats[bear[property]] += 1;     }     for (const value of valuesArray) {       stats[value] = (stats[value] / this.data.length) * 100;     }     return stats;   } } function randomBears(numberOfBears) {   const bearGenerator = new BearGenerator();   const bears = [];   for (let i = 0; i < numberOfBears; i++) {     bears.push(bearGenerator.createRandomBear());   }   const dataProcessor = new DataProcessor(bears);   console.log("Favorite Food Stats:");   console.log(dataProcessor.getStatsFor(bearGenerator.foods, "favoriteFood"));   console.log("Type Stats:");   console.log(dataProcessor.getStatsFor(bearGenerator.types, "type"));   console.log("Color Stats:");   console.log(dataProcessor.getStatsFor(bearGenerator.colors, "color"));   console.log("Aggression Stats:");   console.log(dataProcessor.getStatsFor([true, false], "isAggressive"));   return bears; }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Hello, I have written my random bear generator but for some reason the code isn't running in my command terminal. Please have a look at it and let me know what I am missing. I followed my teachers instructors and lectures, but it doesn't run on another compiler either.

class Bear {
  constructor(type, color, weight, favoriteFood) {
    this.type = type;
    this.color = color;
    this.weight = weight;
    this.favoriteFood = favoriteFood;
    if (this.weight === 700 || this.type === "Little Bear" || this.type === "Baby Bear") {
      this.isAggressive = false;
    } else if (this.weight === 1200 || this.type === "Papa Bear" || this.type === "Black Bear") {
      this.isAggressive = true;
    } else {
      this.isAggressive = Math.random() < 0.5;
    }
    if (this.type === "Winnie the Pooh Bear" && this.favoriteFood !== "Honey") {
      throw new Error("Winnie the Pooh Bear must have Honey as his favorite food.");
    }
  }
}

class BearGenerator {
  get types() {
    return [
      "Winnie the Pooh Bear",
      "Yogi Bear",
      "Boo-boo Bear",
      "Paddington Bear",
      "Mama Bear",
      "Papa Bear",
      "Baby Bear",
      "Little Bear",
      "Teddy Bear",
      "Smokey Bear",
    ];
  }
  get colors() {
    return [
      "Red",
      "Blue",
      "White",
      "Indigo",
      "Green",
      "Teal",
      "Fuchsia",
      "Brown",
      "Violet",
      "Black",
    ];
  }
  get foods() {
    return [
      "Honey",
      "Pizza",
      "Burger",
      "Burrito",
      "Wings",
      "Spaghetti",
      "Steak",
    ];
  }
  createRandomBear() {
    const type = this.types[Math.floor(Math.random() * this.types.length)];
    const color = this.colors[Math.floor(Math.random() * this.colors.length)];
    const weight = Math.floor(Math.random() * 1250) + 250;
    const favoriteFood = this.foods[Math.floor(Math.random() * this.foods.length)];
    return new Bear(type, color, weight, favoriteFood);
  }
}

class DataProcessor {
  constructor(data) {
    this.data = data;
  }
  getStatsFor(valuesArray, property) {
    const stats = {};
    for (const value of valuesArray) {
      stats[value] = 0;
    }
    for (const bear of this.data) {
      stats[bear[property]] += 1;
    }
    for (const value of valuesArray) {
      stats[value] = (stats[value] / this.data.length) * 100;
    }
    return stats;
  }
}

function randomBears(numberOfBears) {
  const bearGenerator = new BearGenerator();
  const bears = [];
  for (let i = 0; i < numberOfBears; i++) {
    bears.push(bearGenerator.createRandomBear());
  }
  const dataProcessor = new DataProcessor(bears);
  console.log("Favorite Food Stats:");
  console.log(dataProcessor.getStatsFor(bearGenerator.foods, "favoriteFood"));
  console.log("Type Stats:");
  console.log(dataProcessor.getStatsFor(bearGenerator.types, "type"));
  console.log("Color Stats:");
  console.log(dataProcessor.getStatsFor(bearGenerator.colors, "color"));
  console.log("Aggression Stats:");
  console.log(dataProcessor.getStatsFor([true, false], "isAggressive"));
  return bears;
}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps with 7 images

Blurred answer
Knowledge Booster
Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education