+ 1
How do i can program a health bar in JavaScript and HTML
For example a health bar
33 ответов
+ 4
health:<progress min=0 max=100 value=35 name=hel id=progres></progress>
you can change its value in js
and color design look. animation shadow in css
+ 2
it is by
document.getElementById("progress").value=23;
+ 2
did you used proper id I mean set the progress bar id to progress
ok try this
<progress id=progress min=0 max=100 name=health value=0></progress>
<button onclick="document.getElementById( 'progress').value+=6;">Click</button>
+ 2
yes then add that code to go drop instead of button
character looses health...
var progressbar=document.getElementById("progress");
function healthdrop(){
health=health-6;
progressbar.value=health;
healthscore.innerHTML=health;
}
+ 2
yes you can put any variable as value
+ 2
I got the error
you used progressbar=document. getElementById("progress").value
now in line 3 you set its value
so it becomes progressbarselement.value.value
use value once
+ 2
no I had no problem with German bien
but code is not being shown
did you corrected that you should use
document.getElementById("progress");
only not ("progress").value;
+ 2
because you used .value twice
first health=document...("progress").value
then you set Heath.value
so it becomes element.value.value
use only once
+ 2
hey Diego what I suggest is you make a separate page please
for testing this
<progress id=progress min=0 max=100 name=health value=0></progress>
<button onclick="function(){
document.getElementById('progress').value+=6;
}">Click</button>
or <button onclick=incprogress()>Click</button>
<script>function incprogress(){
document.getElementById("progress").value+=6;}</scrip t>
+ 2
the spelling of heathbar at innerHTML is also wrong correct it.
one suggestion that instead of alert prompt there
you can use <input type=text id=input>
and then access's it using js document.getElementById("input").value;
+ 2
ok I will answer tomorrow it is too night here
I will see it in morning zzz...
+ 2
i live in India 🇮 ndia
+ 2
in health bar alpha
you declared variable called health bar and set value of not heathbar but progress which is showing error change it
+ 2
I too was getting same error in my program
it is because var element=document.getElementById(element)
doesn't work in sololearn so you have to replace it with document.getElementById( directly I don't why but you can see my code
+ 2
there is only one code as public see it's js section I made the var comment there is other problem too wait I will see all your code I can't now becuase it's time to sleep in India 😀
+ 2
hey Diego problem is solved move the line var=hpyou before the function
and make the attack 4e function
+ 1
Thanks
+ 1
How I can change the value with JavaScript?😅
+ 1
Thanks twice
+ 1
I've written this and it don't work:
var hpyou = 100
var you = document.getElementById("progress").value = hpyou
<progress min="0" max="100"></progress>