Jump to content

Dabby

Members
  • Posts

    16
  • Joined

  • Last visited

Posts posted by Dabby

  1. <ol><li>How many items do you want to create?<br><input type="radio" id="five" name="amount" value="5"><label for="five">5</label><br><input type="radio" id="ten" name="amount" value="10"><label for="ten">10</label><br><input type="radio" id="fifteen" name="amount" value="15"><label for="fifteen">15</label><br></li></ol>

     

    As many as the user indicates on the radio button. But once i clear the scene, i want the loop to start all over AT 0

  2. Hello,

    I am writing a code that allows user create item, select amount to be created, name it and choose a color for it.

    I have a global counter that is supposed to keep count of items created and also give each item create unique id.

    The issue is when i click to create item, the ids do not increment.

    How do i increment counter, save items in array and reset counter?

    This is what i have tried.

     

     

    var items = []; window.onload = init; var counter = 0; var radioButton = 0; function init() { var create = document.getElementById("create"); create.onclick = create; } function create() { var nameInput = document.getElementById("name"); var name = nameInput.value; var colorSelect = document.getElementById("color"); var colorOption = colorSelect.options[colorSelect.selectedIndex]; var color = colorOption.value; if (name == null || name == "") { alert("please enter a name"); return; } for (var i = 0; i < data.elements.amount.length; i++) { if (data.elements.amount.checked) { var amount = data.elements.amount.value; } } for (radioButton = 0; radioButton < amount; radioButton++) { var div = document.getElementById("arena"); var div = document.createElement("div"); var newId = div; newId = radiobutton; div.id = newId; div.name = name;

    }

     

    This is the HTML for to create item

     

    <ol>

    <li>How many items do you want to create?<br> <input type="radio" id="four" name="amount" value="4"> <label for="five">4</label><br> <input type="radio" id="eight" name="amount" value="8"> <label for="ten">8</label><br> <input type="radio" id="twelve" name="amount" value="12"> <label for="fifteen">12</label><br> </li> </ol>

     

    Thanks in advance for your help

  3. So sorry i double posted. Didn't know i wasn't suppposed to.

    I'm learning Javascript newly and its still kind of confusing. I've edited my codes to this

    <!doctype html> <html lang="en"> <head> <title>Mad Lib</title> <meta charset="utf-8"> <script> window.onload = init; function init() { var button = document.getElementById("submit"); button.onclick = goMad; } function goMad() { var story = Var story = ["Hey", "comeon", "car", "pretty"]; var inputs = document.getElementsByTagName("inputs"); var div = document.getElementById("story"); var words = story.value; div.innerHTML = story; goMad = story.value; } </script> </head> <body> <form> <label for="exclamation">Exclamation:</label> <input id="exclamation" type="text" size="20"> <br> <label for="adverb">Adverb:</label> <input id="adverb" type="text" size="20"><br> <label for="noun">Noun:</label> <input id="noun" type="text" size="20"><br> <label for="adjective">Adjective:</label> <input id="adjective" type="text" size="20"><br> <input type="button" id="submit" value="Go Mad!"> </form> <div id="story"> [0] + "! he said " + [1] + " as he jumped into his convertible " + [2] + " and drove off with his " + [3] + " wife." </div> </body> </html>

     

    I'm thinking of an array Var story = ["Hey", "comeon", "car", "pretty"]; But i don't know how to plugs these words into the sentence(div story) that is revealed after the user clicks the Go Mad! button.

  4. please what do i do to get the words typed in the box by the user to appear when the goMad button is clicked?

    e.g if the exclamation is Hey!, how do i get it to show?

     

    <!doctype html> <html lang="en"> <head> <title>Mad Lib</title> <meta charset="utf-8"> <script> window.onload = init; function init() { var button = document.getElementById("submit"); button.onclick = goMad; } function goMad() { var words = 0; var inputs = document.getElementsByTagName("input"); var story = words[0] + "! he said " + words[1] + " as he jumped into his convertible " + words[2] + " and drove off with his " + words[3] + " wife." for (var i = 0; i < inputs.length; i++) { var addendString = inputs.words; } var div = document.getElementById("story"); div.innerHTML = story; } </script> </head> <body> <p> This is a MadLib game. You are required to provide four words, an exclamation, an adverb, a noun, and an adjective. Fill in the box below and click the Go Mad button to reveal the sentence. </p> <form> <p> </p> <label for="exclamation">Exclamation:</label> <input id="exclamation" type="text" size="20"> <br> <p>He said,</p> <label for="adverb">Adverb:</label> <input id="adverb" type="text" size="20"><br> <p>as he jumped into his convertible</p> <label for="noun">Noun:</label> <input id="noun" type="text" size="20"><br> <p>and drove off with his</p> <label for="adjective">Adjective:</label> <input id="adjective" type="text" size="20"><br> <p>wife</p> <input type="button" id="submit" value="Go Mad!"> </form> <div id="story"> </div> </body> </html>

  5. please what do i do to get the words typed in the box by the user to appear when the goMad button is clicked?

    e.g if the exclamation is Hey!, how do i get it to show?

     

    <!doctype html> <html lang="en"> <head> <title>Mad Lib</title> <meta charset="utf-8"> <script> window.onload = init; function init() { var button = document.getElementById("submit"); button.onclick = goMad; } function goMad() { var words = 0; var inputs = document.getElementsByTagName("input"); var story = words[0] + "! he said " + words[1] + " as he jumped into his convertible " + words[2] + " and drove off with his " + words[3] + " wife." for (var i = 0; i < inputs.length; i++) { var addendString = inputs.words; } var div = document.getElementById("story"); div.innerHTML = story; } </script> </head> <body> <p> This is a MadLib game. You are required to provide four words, an exclamation, an adverb, a noun, and an adjective. Fill in the box below and click the Go Mad button to reveal the sentence. </p> <form> <p> </p> <label for="exclamation">Exclamation:</label> <input id="exclamation" type="text" size="20"> <br> <p>He said,</p> <label for="adverb">Adverb:</label> <input id="adverb" type="text" size="20"><br> <p>as he jumped into his convertible</p> <label for="noun">Noun:</label> <input id="noun" type="text" size="20"><br> <p>and drove off with his</p> <label for="adjective">Adjective:</label> <input id="adjective" type="text" size="20"><br> <p>wife</p> <input type="button" id="submit" value="Go Mad!"> </form> <div id="story"> </div> </body> </html>

×
×
  • Create New...