add Exceptions

pull/14/head
Bastien JACQUELIN 2 years ago
parent 7857f56201
commit e4a20f0bc9

@ -15,7 +15,7 @@
</section>
<script src="../Model/Card.js"></script>
<script src="../Model/Card5.js"></script>
<script src="test.js"></script>
<script src="main.js"></script>
</body>
</html>

@ -0,0 +1,5 @@
class EmptyParamaterException extends Error{
constructor(field){
super(`Field ${field} missing`);
}
}

@ -4,8 +4,14 @@
console.log("~#Test#~");
let card4 = new Card('red','2','losange','full');
console.group('Carte 4 attributes');
console.log(`carte de 4 elements : ${card4.color}`);
console.groupEnd();
let card5 = new Card5('blue','2','losange','full','pointillet');
console.group('Carte 5 attributes');
console.log(`carte de 5 elements : ${card5.outline}`);
console.log(`carte de 5 éléments instance de 5: ${card5 instanceof Card5}`);
console.log(`carte de 5 éléments accès par méthode : ${card5.getAttributes()[0]}`);
console.log(`carte de 5 éléments accès par méthode idx 0: ${card5.getAttributes()[0]}`);
console.log(`carte de 5 éléments accès par méthode idx 4: ${card5.getAttributes()[4]}`);
let errCard = new Card5('blue','','losange','full','pointillet');
console.groupEnd();

@ -1,5 +1,17 @@
class Card{
constructor(color, number, shape, filling){
if(!color){
throw new EmptyParamaterException('Color');
}
if(!number){
throw new EmptyParamaterException('Number');
}
if(!shape){
throw new EmptyParamaterException('Shape');
}
if(!filling){
throw new EmptyParamaterException('Filling');
}
this.color=color;
this.number=number;
this.shape=shape;
@ -15,7 +27,7 @@ class Card{
* @author Bastien Jacquelin
*/
getAttributes(){
return [this.color,this.number,this.shape,this.filling,null];
return [this.color,this.number,this.shape,this.filling];
}
}//export {Card}

@ -3,6 +3,9 @@
class Card5 extends Card {
constructor(color, number, shape, filling, outline){
super(color,number,shape,filling);
if(!outline){
throw new EmptyParamaterException('Outline');
}
this.outline=outline;
}
/**
@ -15,7 +18,8 @@ class Card5 extends Card {
* @author Bastien Jacquelin
*/
getAttributes(){
return [this.color,this.number,this.shape,this.filling,this.outline];
// return [this.color,this.number,this.shape,this.filling,this.outline];
return super.getAttributes().concat(this.outline);
}
}
// export {Card5};
Loading…
Cancel
Save