+ 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
6th Jun 2021, 3:37 AM
Ollie Q
Ollie Q - avatar
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)
6th Jun 2021, 3:37 AM
visph
visph - avatar
0
as you get value as string you should convert it to number to avoid string concanetation: Number(string_value)+1
6th Jun 2021, 3:59 AM
visph
visph - avatar
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 ;)
6th Jun 2021, 4:09 AM
visph
visph - avatar
0
say you want assign to paragraph a string with a line break: document.getElementById("def").innerHTML = "Hello<br>World";
6th Jun 2021, 4:11 AM
visph
visph - avatar
0
search in Q&A: this question has been posted a lot of time ^^
6th Jun 2021, 4:18 AM
visph
visph - avatar
0
what case?
6th Jun 2021, 4:21 AM
visph
visph - avatar
0
Hi Harsh Kishore Just added a parseInt to convert the value of x to an integer. It should work now
6th Jun 2021, 4:23 AM
Ollie Q
Ollie Q - avatar
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
6th Jun 2021, 4:29 AM
Ollie Q
Ollie Q - avatar
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"; }
6th Jun 2021, 4:33 AM
visph
visph - avatar
0
document.getElementById("abc").innerHTML = parseInt(x) + 1;
6th Jun 2021, 4:39 AM
visph
visph - avatar
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 ;)
6th Jun 2021, 4:41 AM
visph
visph - avatar
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)
6th Jun 2021, 4:44 AM
visph
visph - avatar
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
6th Jun 2021, 4:56 AM
visph
visph - avatar
0
Hi Harsh Kishore Great to see some of your work. Happy coding!
9th Jun 2021, 7:41 AM
Ollie Q
Ollie Q - avatar
9th Jun 2021, 7:53 AM
visph
visph - avatar
- 1
明亮
7th Jun 2021, 12:31 PM
泽 X
- 1
i don't know about Syntex work. I am a beginner help please
8th Jun 2021, 1:37 AM
Ayush kumar Gupta