loading
open in
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
class Letter {
  constructor(value) { 
        this.value = value;
    }
    
  iam() { 
   return `I am the ${this.constructor.name} ${this.value}`;
   }
   
  alphabet() { 
   return this.value + " is letter No." + '0abcdefghijklmnopqrstuvwxyz'.indexOf(this.value) + " in the alphabet";
  }
}



let test = new Letter("a");
console.log(test.iam());
console.log(test.alphabet());

class Vowel extends Letter {
  constructor(value) { 
  super(value);
  if (["a","e","i","o","u"].indexOf(value) === -1)
        throw new SyntaxError("Invalid vowel");
  }
}


let test2 = new Vowel("i");
console.log(test2.iam());
console.log(test2.alphabet());


let test3 = new Vowel("d"); // Raises syntax error in constructor
Native Browser JavaScript