未捕获的类型错误:无法在Javascript

时间:2018-10-23 05:52:53

标签: uncaught-typeerror

我只是在学习使用Javascript编写代码,但是在我的浏览器Chrome和Mozilla上出现错误

这是Javascript代码

//使用JSCRIPT访问您的标签

var bouns = document.getElementById(p1);
console.log("What type of element is this: ", bouns.nodeType);
console.log("This is the  innerHTMLelement: ", bouns.innerHTML);
console.log("Does the Id have Child Node: ", bouns.childNodes);

var listItem = document.getElementsByTagName("li");
document.write("We Have: ",listItem.length, "Items");

var a = 1;
var b = 2;

if (b<a ){
var result = a + b;
document.write("The Addition of our variables becomes   <br/>", result);
}
else {
document.write("WE DON'T TAKE SHIT!<br/>");
}

//测试数字和字符串的加法

var fig1 = 5;
var fig2 = 8;
var fig3 = "5";
var fig4 = "8";
document.write(fig1 + fig2 , "<br/>");

document.write(fig3 + fig4, "<br/>");

///将转换后的字符串添加到其他号码

var convertToNum = Number(fig3)
document.write("This is the RESULT of Adding String(To Number) with Number", convertToNum + fig1, "<br/>");

//使用数学对象来舍入数字

var fig5 = 5.99;
var fig7 = Math.round(fig5);

document.write("This number has been rounded off",fig7,"<br/>");

//数学对象生成随机数

var Value = Math.random();
document.write(Value,"<br/>");

//使用对象生成一对一到六个的正义

var diceFace = Math.floor(Math.random()*6 + 1);
document.write(diceFace,"<br/>");

var characterLength = "My Faith looks Up to thee, Thou Lamb of Calvary!";
bobo = characterLength.charAt(22);
document.write("Print out the 20th character letter<br/>", bobo);

//使用Search方法在字符串变量中定位字母的位置

locate = characterLength.search("C");
document.write("<br/> Tell Us where the \e is " ,locate);

//使用日期功能

var date = new Date();
document.write("<br/>",date,"<br/>");

var getYear = date.getFullYear();
document.write(getYear,"<br/>");

//使用对象和修改对象

var Person = new Object();
Person.pName = "AdeBOBO";
Person.pAge = 40;
Person.pSex = "Male";
document.write(Person.pSex);

///通过另一种方法来处理对象

var PersonAlt = {name: "Bolu", Complexion: "White", State: "Ondo"};

这是我的HTML代码

<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title> Template Church </title>
</head>

<body>
<form>
Width: <br/> <input type="text" id="width"> <br>
Height: <br/> <input type="text" id = "height"> <br/>
<input type="button" onclick="Calc()" value ="Get Area">
<input type="text" id="answer" size="12px">
</form>

<header>
<h2>WHO HAS THE FINAL SAY</h2>
<a href="">Home</a>
<a href="#">Mission</a>
<a href="#">Contact</a>
</header>

<div id="mainbody">
<p id="p1">This is the PARAGRAPH in the body of the div section in the Html Document</p>
<p id="article"><br/> This is another ParaTABLE in the body of the div section in the Html Doc Man</p>
<ul>
<li>Premium</li>
<li>English</li>
<li>Baddy</li>
</ul>
</div>
<script type="text/javascript" src="church template.js"></script>
</body>
</html>

0 个答案:

没有答案