class Submarine{
isSubmerged = true;
constructor(totalTorpedos, torpedosFired){
this.totalTorpedos = totalTorpedos;
this.torpedosFired = torpedosFired;
}
fireTorpedo(){
console.log(`${this.torpedosFired} torpedos fired,${this.totalTorpedos - this.torpedosFired} torpedos left`);
this.isSubmerged = false;
}
checkSubmerge(){
if(this.isSubmerged === true){
console.log("Submarine Submerged");
}else{
console.log("Submarine Resurface");
}
}
submerge(){
this.checkSubmerge();
this.fireTorpedo();
this.checkSubmerge();
}
}
const submarine = new Submarine(10,2);
submarine.submerge();
Comments
Leave a comment