特定のWebサイトでの初心者のチュートリアルに続いて、プレゼンターのコードは動作しますが、私のものはありません。 (私は私達が全く同じコードを持っていると信じています)。彼のコードは、警告ボックスに「ちょうど最初の関数を呼び出す」と書かれています。しかし、私のコードはその点に達していません。何か不足していますか?JSコードのトレースとデバッグ
私のhtmlページ
<html>
<head>
<title>Debugging and Tracing through code</title>
<script src="tracing.js"></script>
</head>
<body>
<p>Example of tracing through code.</p>
<h1 id="mainHeading">Interesting Headline</h1>
</body>
</html>
私のjsのコード
function firstFunction() {
secondFunction();
}
function secondFunction() {
thirdFunction();
}
function thirdFunction() {
fourthFunction();
}
function fourthFunction() {
headline.innerHTML = "You clicked the headline!";
}
var headline = document.getElementById("mainHeading");
alert("Ive grabbed main heading");
headline.onclick = function() {
alert("just about to call first function");
firstFunction();
alert("I've called first function");
};
エラー
2 Missing 'use strict' statement. secondFunction();
2 Expected 'secondFunction' at column 5, not column 4. secondFunction();
2 'secondFunction' was used before it was defined. secondFunction();
6 Missing 'use strict' statement. thirdFunction();
6 'thirdFunction' was used before it was defined. thirdFunction();
10 Missing 'use strict' statement. fourthFunction();
10 'fourthFunction' was used before it was defined. fourthFunction();
14 Missing 'use strict' statement. headline.innerHTML = "You clicked the headline!";
14 'headline' was used before it was defined. headline.innerHTML = "You clicked the headline!";
18 'alert' was used before it was defined. alert("Ive grabbed main heading");
20 Missing 'use strict' statement. alert("just about to call first function");
あなたはID "mainHeading" とhtml要素を持っていない...以下を参照してください? – Snowmonkey
あなたのマークアップを投稿してください。 – TheValyreanGroup
あなたのコードをコピー&ペーストし、jsfiddle:https://jsfiddle.net/snowMonkey/u7t7rcna/として実行しました。うまくいきます。 – Snowmonkey