Menu
Coddy logo textTech

אתגר סיכום

חלק מהיחידה תכנות מונחה עצמים במסלול ה-JavaScript של Coddy. שיעור 38 מתוך 56.

challenge icon

אתגר

ניתנו לך המחלקה Shape ושתי מחלקות יורשות. השלימִי אותן באמצעות מושגי פולימורפיזם.

  1. במחלקה Circle: דרסי את describe() כך שתחזיר: "This is a circle with radius [radius]"
  2. במחלקה Square: דרסי את describe() כך שתחזיר: "This is a square with side [side]"

נסו בעצמכם

import { Shape } from './shapes.js';
import { Circle } from './shapes.js';
import { Square } from './shapes.js';

// קוד בדיקה - אין לשנות
const circle = new Circle(5);
const square = new Square(10);

console.log(circle.describe()); // צפוי: "This is a circle with radius 5"
console.log(square.describe()); // צפוי: "This is a square with side 10"

כל השיעורים ביחידה תכנות מונחה עצמים

תרגלו בעצמכם: קומפיילר JavaScript אונליין