Jump to content

Dabby

Members
  • Posts

    16
  • Joined

  • Last visited

Profile Information

  • Gender
    Male

Dabby's Achievements

Newbie

Newbie (1/7)

0

Reputation

  1. @davej, worked well but please t what point does both the counter and the items array get reset. I tested your code an after i cleared, it set back as if the page had just loaded. What part of the code makes it act that way?
  2. <ol> <label for="name">Name: </label> <input type="text" id="name" size="30"> </li> <li>Pick a color: <br> <select id="color"> <option value="blue">Red</option> <option value="pink">Orange</option> <option value="grey">Yellow</option> </select> </li> Sorry i should have posted this along side. </ol>
  3. <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
  4. Yes when they want 15 i create 15, when the want 5 i create 5 etc. My code creates that already. Only issue is after creating 15 or 5 as the case may be, when i clear my page, i would want to reset my counter. Thank U
  5. I'm trying to create boxes with different colors.
  6. The name of item, color of item and id of item. I have part of my code working. But i am having difficulties resetting counter after i clear the field. I have this code for clearing the field. var clear = document.getElementById("clear"); clear.onclick = clear;
  7. 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
  8. 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.
  9. 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>
  10. 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>
  11. for instancevar cars = [23, 5, 12, 4]How do i add the numbers using a for loop?
×
×
  • Create New...