#I need to understand why this piece of coding is only showing the first variable(just learning java)

31 messages · Page 1 of 1 (latest)

wise portal
#

I need to understand why this piece of coding is only showing the first variable(just learning java)

regal sinewBOT
#

Despite their similarity in name, Java and JavaScript are different languages and are not compatible with each other. This is a JavaScript server, but there are likely many Java-specific servers out there.

plush crown
#

Why would it not?

#

The let-declared variable in the block ({}) is only visible in this block

wise portal
#

Oh i am sorry. Its Javascript

#

Okay, so the variable outside the block is considered Global? and we can only print global?

plush crown
#

No

#

What you print is the variable in the scope

#

The block is another scope

#

See #faq to learn modern JS

#

if you copy paste the log in the block, you will see first 2 then 15555

wise portal
#

I understand now, thank you p35

#

@sharp frigate I am still learning to understand majority of it. As for .innerHTML i can only assume its considered a function within js, but i am not on that lesson yet. I was thinking maybe if i do change that then i would be able to output both of those number, but that is way beyond my scope rn.

#

One thing as a time, lmao. I do appreciate both of your guys help!

sharp frigate
#

ya my comment didn't really apply, that's why I deleted it...
it's generally bad to use innerHTML but is fine here. just look into the security implications at some point.
no, innerHTML is not a function. it's a property of the element object.

wise portal
#

I am confusing myself because i only know Python, so thank you.

Wait!

#

How can it not be a function?

plush crown
#

It's a getter/setter

wise portal
#
words = str.split()
print(len(words))```

.split()<----this could be considered property of the element object no? The object would be ``str``
#

or should i stop just comparing the two languages? ahah

plush crown
#

There's Impatient JS ( #faq ) if you know another language

#

python is relatively close to JS however

wise portal
sharp frigate
#

yes, .split() is both a property and a function 😉 (but not a property of Element objects)

wise portal
#

Gracias!!

plush crown
#

Properties are ./[] accessed. A method is a function, but not every property is a function

wise portal
#
Generative AIs (e.g. ChatGPT)
W3Schools
FreeCodeCamp
geeksforgeeks```

May i ask why not w3school, and geeksforgeeks? Those are like my heaven
regal sinewBOT
sharp frigate
#

(same for g4g AFAIK)

wise portal
#

Cool