cosole.logが表示されずエラーも表示されない。
class Element { constructor(name, buildYear) { this.name = name; this.buildYear = buildYear; } } class Park extends Element { constructor(name, buildYear, area, numTrees) { super(name, buildYear); this.area = area; this.numTrees = numTrees; } treeDensity() { const density = this.numTrees / this.area; console.log(`${this.name} has a tree density of ${density} trees per square km.`); } } class Street extends Element { constructor(name, buildYear, length, size = 3) { super(name, buildYear); this.length = length; this.size = size; } classifyStreet() { const classification = new Map(); classification.set(1, 'tiny'); classification.set(2, 'small'); classification.set(3, 'normal'); classification.set(4, 'big'); classification.set(5, 'huge'); console.log(`${this.name},build in ${this.buildYear}, is a${classification.get(this.size)}street.`); } } //1, 木の密度を調べたい。 const allParks = [new Park('Green park', 1987, 0.2, 215), new Park('National Park', 1894, 2.9, 3541), new Park('Oak Park', 1953, 0.4, 949) ]; const allStreets = [new Street('Ocean Avenue', 1999, 1.1, 4), new Street('Evergreen Street', 2008, 2.7, 2), new Street('4th Street', 2015, 0.8), new Street('Sunset Boulevard', 1982, 2.5, 5)]; function calc(arr) { const sum = arr.reduce((prev, cur, index) => prev + cur, 0); //[3,5,6] return [sum, sum / arr.length]; } function reportParks(p) { console.log('-------Parks report--------'); //density p.forEach(el => el.treeDensity()); //Average age const ages = p.map(el => new Date().getFullYear() - el.buildYear); const [totalAge, avgAge] = calc(ages); console.log(`Our ${p.length} parks have an average of ${avgAge} years`); //which park has mora than 1000 trees } function reportStreets(s) { }![イメージ説明](bd4cf3e7fa058fab0c41c377e8ecc8bd.png)
teratailは質問内容の編集ができるので、変更がある場合は新しい質問をするのではなく編集してください。また、こちらの質問を削除されるよう運営に連絡されることをお勧めします。 https://teratail.com/help#delete-question https://teratail.com/contact/input
回答1件
あなたの回答
tips
プレビュー