Problem: I'm trying to create a constructor function named Wizard that takes 2 parameters: name and spells, and then create a Wizard object:
"Each particular instance of wizard must have a name property (a string), a spells property which is an array of strings, and a castSpell method capable of returning a random spell in string format."
The object has the following properties: name is "Gorrok" (string), and spells is "abracadabra" and "cadabraabra" (array).
Objective: to invoke the castSpell method to display a random spell like so: Gorrok : abracadabra
Code: I've only written the following code so far, and I'm stuck at this stage!
function Wizard(name, spells){
this.name = name;
this.spells = [spells];
this.castSpell = function(){
var v = Math.random();
if (v >= 1)
document.write(this.name + " : " + this.spells[0]);
else
document.write(this.name + " : " + this.spells[1]);
}
}
var w = new Wizard("Gorrok", "abracadabra", "cadabraabra");
w.castSpell();