My object isn’t displaying when i use the javascript constructor method to create an object
تبليغيرجى شرح بإيجاز لمإذا تشعر أنك ينبغي الإبلاغ عن هذا السؤال.
<html lang=”en”>
<head>
<meta charset=”UTF-8″>
<meta http-equiv=”X-UA-Compatible” content=”IE=edge”>
<meta name=”viewport” content=”width=device-width, initial-scale=1.0″>
<title>Document</title>
</head>
<body>
<h1>CREATE JAVASCRIPT OBJECTS USING OBJECT-LITERAL</h1>
<P id=”text”></P>
<script language=”javascript” type=”text/javascript”>
document.write(“OBJECT CREATION”);
function char(name, anime, specie){
this.name = name;
this.anime = anime;
this.specie = specie;
}
var character = char(“Goku”, “dragonballz”, “saiyan”);
document.getElementById(“text”).innerHTML = character.name + ” is from ” + character.anime + ” and he is a super ” + character.specie + ” Alien “;
</script>
</body>
</html>
So… As you can see, I tried using the javascript constructor method to create an object, And its not dispaying, In the console it said character which is the variable name is undefined.
I’m just currently learning javascript, so i would love to get some help.
أضف إجابة