2017-03-28 7 views
-3

だから、私は狂ったlibを作るためにjavascriptとhtmlを使わなければなりません。私は値を入力してボタンを押すようにユーザーに求めていて、入力した値を使ってストーリーを生成することになっています。なぜ私の狂ったライブラリはコンパイルされませんか?

<ul> 
    <li>Your Name: <input type="text" id="name"></li> 
    <li>Adjective: <input type="text" id="adjective"></li> 
    <li>State: <input type="text" id="state"></li> 
    <li>Animal: <input type="text" id="animal"></li> 
    <li>Month: <input type="text" id="month"></li> 
    <li>Adjective: <input type="text" id="adjective2"></li> 
    <li>Animal: <input type="text" id="animal2"></li> 
    <li>Object: <input type="text" id="object"></li> 
</ul> 
<button id="ready-button">Ready</button> 
<div id="story"></div> 
<script> 
    function madLib() { 
     var storyDiv = document.getElementById("story"); 
     var adjective = document.getElementById("adjective").value; 
     var noun = document.getElementById("noun").value; 
     var state = document.getElementById("state").value; 
     var animal = document.getElementById("animal").value; 
     var month = document.getElementById("month").value; 
     var adjective2 = document.getElementById("adjective2").value; 
     var animal2 = document.getElementById("animal2").value; 
     var object = document.getElementById("object").value; 
     storyDiv.innerHTML ="One day, " + name + " was in the backwoods of " + state + " riding their pet " + animal + " it wasn't often that " + name + " got the chance to do this so they always made the most of their adventure. Usually, it was a fun experience until that one day in " + month + " they were minding their own business when all of the sudden the " + adjective2 + " " + animal2 + " jumped out from behind a small " + object + ". " + name + " could not beieve what they were seeing."; 
    } 
    var readyButton = document.getElementById('ready-button'); 
    readyButton.addEventListener('click', madLib); 
</script> 
+0

であるべきで?

var noun = document.getElementById("noun").value; //document.getElementById("noun") will be undefined because there is no "noun element" 

を持って 何がうまくいかない?エラー? – Carcigenicate

+0

私はすべての値を入力できますが、入力されたすべての値を含むストーリーは表示されません。 – smithky3

答えて

0

あなたの物語の値をつかむときに「名前」と混ざっ「名詞」を得たようだ:

は、ここに私のHTMLです。あなたは<input type="text" id="name"></li>を持って、あなたはあなたの物語の中でname変数を使用して数回、しかしmadLib機能では、おそらく

var name = document.getElementById("name").value; 
関連する問題