+ 2
Hi Harsh Kishore
Here is your fixed code
https://code.sololearn.com/Wf1dFmjL1WXg/?ref=app
2 things:
1 .value is used to get value from input tags
2. .textContent = is used to set value of text in p tags
Also did you want to add one to the value of #abc? Because i added that to
0
p elements have no 'value' properties (only input/form fields have one)... for most of elements you should assign the 'textContent' property ;) (or innerHTML if you want to replace html code)
0
as you get value as string you should convert it to number to avoid string concanetation:
Number(string_value)+1
0
as you use value or textContent: by assigning an html string wich will be parsed on the fly to update the page/element content ;)
0
say you want assign to paragraph a string with a line break:
document.getElementById("def").innerHTML = "Hello<br>World";
0
search in Q&A: this question has been posted a lot of time ^^
0
what case?
0
Hi Harsh Kishore
Just added a parseInt to convert the value of x to an integer. It should work now
0
parseInt() converts the value in the parentheses to an integer if possible. So if you had the string “43” and passed it into the parseInt() function it would convert it from a string to an integer and allow you to use mathematical operations such as + or - on it
Also #abc refers to the input tag as it’s id is abc and the # is used to reprent id in css
0
Harsh Kishore first you must distinguish between assignement operator (=) and comparison operator (==)...
then you make an if..else statement as:
if (x==1) {
htmlElementReference.textContent = "true";
}
else {
htmlElementReference.textContent = "false";
}
0
document.getElementById("abc").innerHTML = parseInt(x) + 1;
0
but in that case, you doesn't need to parse value as html: better to use textContent...
also, using Number() allow int or float... there's also a parseFloat() function ;)
0
parseFloat() allow int as well...
difference between parse{Type} and Number is that formers allow numbers with anything after (ignored), while later only accept numbers:
parseFloat("2px") => 2
Number("2px") => NaN (Not a Number special value)
0
htmlElementReference was just a meaningful name to say "a variable wich hold the reference of the targeted element ^^
the values assigned were just to show what apply in wich case...
your code must be:
if (x == 1) {
document.getElementById("def").textContent = "welcome";
} else {
document.getElementById("def").textContent = "sorry try again";
}
prefer to use textContent when you not need to put html tags ;P
0
Hi Harsh Kishore
Great to see some of your work.
Happy coding!
0
Harsh Kishore view this one, and keep coding :)
https://code.sololearn.com/Wb23LVlcPMMv/?ref=app
- 1
明亮
- 1
i don't know about Syntex work. I am a beginner help please