0
Hi pls see my sentence generator code and then pls tell what is wrong with it..
14 Respostas
+ 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 + ".")
}
+ 2
Make, um, something like a paragraph under button, like <p id=mySentence>, and then inside the script,
document.getElementById("mySentence").innerHTML = "Hello"
+ 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 + "."
}
+ 2
You don't need any script tags since SoloLearn provides us with a space for js codes.
+ 2
I'm really glad that I can help.
+ 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 + ".");
}
+ 1
It doesn't work!?!? Have you checked the IDs of all the input fields?
0
no cheeze,this does not work...anyways thanks for your effort...
0
yes...checked...still not working...
0
thanks cheez , now it works ....
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....
0
pls specify a little more...i am a little weak with javascript
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
0
wow you are a real genius...this worked for me..thanks a lot for responding me ...