0

Hi pls see my sentence generator code and then pls tell what is wrong with it..

28th Dec 2016, 4:14 PM
Rithik Bhandari
Rithik Bhandari - avatar
14 Answers
+ 2
geez, make sure the input fields have the correct IDs. The input fields for age and state have missing IDs.. For the HTML, <input id=name placeholder="Name"> <input id=age placeholder="Age"> <input id=state placeholder="State"> <button onclick="generate()"> For the JS, function generate() { var name = document.getElementById("name").value ; var age = document.getElementById("name").value ; var state = document.getElementById("name").value ; alert("Hello, I am " + name + ", I am " + age + " years old. I live in " + state + ".") }
2nd Jan 2017, 5:15 PM
David Sebastian Keshvi Illiakis
David Sebastian Keshvi Illiakis - avatar
+ 2
Make, um, something like a paragraph under button, like <p id=mySentence>, and then inside the script, document.getElementById("mySentence").innerHTML = "Hello"
2nd Jan 2017, 5:30 PM
David Sebastian Keshvi Illiakis
David Sebastian Keshvi Illiakis - avatar
+ 2
That's an amazing calculator you got there. I am actually surprised how you stated that you were weak at javascript.. Make a paragraph just under the button and specify the ID to be something like "sentence". Then, for the script, function generate() { var name = document.getElementById("name").value ; var age = document.getElementById("name").value ; var state = document.getElementById("name").value ; document.getElementById("sentence").innerHTML = "Hello, I am " + name + ", I am " + age + " years old. I live in " + state + "." }
2nd Jan 2017, 5:36 PM
David Sebastian Keshvi Illiakis
David Sebastian Keshvi Illiakis - avatar
+ 2
You don't need any script tags since SoloLearn provides us with a space for js codes.
2nd Jan 2017, 5:40 PM
David Sebastian Keshvi Illiakis
David Sebastian Keshvi Illiakis - avatar
+ 2
I'm really glad that I can help.
2nd Jan 2017, 5:43 PM
David Sebastian Keshvi Illiakis
David Sebastian Keshvi Illiakis - avatar
+ 1
function Generate(){ var name=document.getElementById("name").value; var age=document.getElementById("age").value; var state=document.getElementById("state").value; document.write("Hi,My Name Is " + name + " and I Am " + age + " years Old. I Live In " + state + "."); }
30th Dec 2016, 2:42 AM
David Sebastian Keshvi Illiakis
David Sebastian Keshvi Illiakis - avatar
+ 1
It doesn't work!?!? Have you checked the IDs of all the input fields?
30th Dec 2016, 9:38 AM
David Sebastian Keshvi Illiakis
David Sebastian Keshvi Illiakis - avatar
0
no cheeze,this does not work...anyways thanks for your effort...
30th Dec 2016, 9:37 AM
Rithik Bhandari
Rithik Bhandari - avatar
0
yes...checked...still not working...
30th Dec 2016, 9:41 AM
Rithik Bhandari
Rithik Bhandari - avatar
0
thanks cheez , now it works ....
2nd Jan 2017, 5:27 PM
Rithik Bhandari
Rithik Bhandari - avatar
0
pls tell me one thing that when it generates the sentence , it redirects to a new page and there displays the sentence.cant this sentence be just below the generate button..if possible , pls tell....
2nd Jan 2017, 5:29 PM
Rithik Bhandari
Rithik Bhandari - avatar
0
pls specify a little more...i am a little weak with javascript
2nd Jan 2017, 5:32 PM
Rithik Bhandari
Rithik Bhandari - avatar
0
thanks for the comment..ok i make a paragraph under the button and give it a id as sentence..then how to link the script ??? shall i copy the whole script in the paragraph in a script tag ??ok..let me try
2nd Jan 2017, 5:39 PM
Rithik Bhandari
Rithik Bhandari - avatar
0
wow you are a real genius...this worked for me..thanks a lot for responding me ...
2nd Jan 2017, 5:43 PM
Rithik Bhandari
Rithik Bhandari - avatar