Why the desired value not showing ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why the desired value not showing ?

I want to display welcome but that is not displayed. Why ? https://code.sololearn.com/WheMqexK9z4o/?ref=app

6th Jun 2021, 10:13 AM
Harsh
Harsh - avatar
6 Answers
+ 6
* getElementById returns the element that has the ID attribute. In add you need to call its value as follows: var x = document.getElementById("abc").value;
6th Jun 2021, 10:22 AM
JaScript
JaScript - avatar
+ 2
7th Jun 2021, 7:08 AM
JaScript
JaScript - avatar
+ 1
Alternatively, you can directly access the "id" attribute value as a global variable: if(abc.value == 10)
6th Jun 2021, 10:53 AM
Solo
Solo - avatar
+ 1
JaScript Thanx friend.
7th Jun 2021, 2:47 AM
Harsh
Harsh - avatar
0
Vasiliy , Does abc.value assigns all var values ?
7th Jun 2021, 2:43 AM
Harsh
Harsh - avatar
0
Yes all. Your function can be abbreviated to: function myFunction() { if (abc.value <= 10) { def.textContent = "Welcome!"; } else { def.textContent = "Sorry! Try Again!"; } } 👇ES6: myFunction=()=>{ def.textContent = abc.value <= 10 ?"Welcome!" :"Sorry! Try Again!"; } Feel free to experiment with your code after making a copy, or comment out first option. For example, you can replace textContent with innerText, and if you replace it with innerHTML, then you can insert tags into the text: def.innerHTML = "<b>Welcome!</b>"
7th Jun 2021, 8:51 AM
Solo
Solo - avatar