0
What's the difference between querySelector and getByClassName ?How can I console out my Sprite in JavaScript?
What is wrong, I try to print out SpritePlease help with JavaScript code, I'm stuck here in my document.selectByClassName https://code.sololearn.com/WSMG536eZ0Cg/?ref=app
32 Antworten
0
replace :
function alertHello = alert(player);
with:
alert(player);
and name has to be a string (vasya) without " ", means it is a variable.
so :
var name = "vasya" ;
+ 2
you don't always have to use window.onload.
you could put your javascript at the end of html. there are many scenarios.
+ 1
add onload function to your code.
window.onload =function() {
//your entire code here
}
document. getElementsByClassName()
add s to "Element"
+ 1
window.onload=function(){
var drink = document.getElementsByClassName("cold");
drink
console.log(drink[1].textContent);
}
+ 1
What is window.onload function, what does it do, when and how it's used? And what is used for document.querySelector and what for is document.getElementBy Id/className/TagName
in 7 hours can't figure out till the end
+ 1
yes everything inside.
otherwise the code will execute before the page is loaded and it will not see your html.
+ 1
window.onload not windows remove s.
+ 1
since now you're using queryselector.
use CSS selector (".cold") not ("cold" ), just like what would you write in css code.
window.onload = function() {
var drink = document.querySelectorAll(".cold")
console.log(drink[1].textContent)
}
+ 1
select first then console.log()
and add } at the end. just try the code above your last reply.
+ 1
Oho I did it
https://code.sololearn.com/WSMG536eZ0Cg/?ref=app
+ 1
var name = "vasya"
var level = 25
var player = "your name is " + name + "and you are " + level + " level"
console.log(player)
function sayHello(name) {
alert("Hi, " + name);
}
sayHello("David");
function door(level) {
if (level < 10) {
alert("return after " + bcd + " levels");}
else if(level >= 10) {
alert("you can pass");
}
}
bcd = 10 - level
door(7);
door(11);
+ 1
you keep using variables before they are created.
the order of lines matters.
and concatenation with + does not need comma (,)
+ 1
it works fine,
it's printing the else statement because you used door(11) after door(7)
+ 1
Question not found kattar, and i wake up and made new problems to fix, why my JavaScript ain't working now? I have loaded windows onload, I have selected by getElementByClass name I have set all variables but it ain't printing what I need...
how do I place the 3 properties the right way inside small-crate?
window.onload = function() {
var armor = "leather"
var sword = "metal"
var gold = 150
var smallCrate =
document.getElementByClassName("small-crate")
smallCrate = gold, sword, armor
alert(smallCrate)
https://code.sololearn.com/WO8zAfu0E633/?ref=app
+ 1
getElementsByClassName
Elements not Element
told you already yesterday.
+ 1
var drink = document.getElementsByClassName("cold");
Array.from(drink).forEach(
function(cold){
drink.textContent += "drinkii"
})
you did not wrap the whole function inside foreach parentheses.
you have a dot . after "drinkii"
you forgot to write "document"
document.getElementsByClassName
0
+ window.onload=function () {}
means execute the javascript code when the entire page is loaded.
without it in your case, javascript execute before the html is loaded so it doesn't see any of your class id...
and it returns undefined.
0
You mean I have to put
windows.onload
{
And absolutely everything from JavaScript here???
}
still don't work with this onload I don't understand
https://code.sololearn.com/WSMG536eZ0Cg/?ref=app
0
It is now undefined!
https://code.sololearn.com/WSMG536eZ0Cg/?ref=app