Couple of questions

KeyboardGod
6 years ago

0

a = window.location.host + ""; b = a.length; c = 4 + ((5 * 10) * 2); d = String.fromCharCode(c, -(41 - Math.floor(1806 / 13)), Math.sqrt(b - 2) * 29, (b * 8) - 29);

I just made the javascript do the work and it gave me the “hats” value.

But..

I didn’t exactly understand how this worked. I know what is happenning here.

I am curious about how the a variable works. I would be really grateful if someone explained it step by step.

5replies
2voices
311views
dimooz
6 years ago | edited 6 years ago

0

Simple as hello.

The a variable stores the server host name where the active page is hosted.
window -> the current opened webpage in your browser
window.location -> the url (web address) of this page (currently opened in your browser)
window.location.host -> the host name extracted from the url
and
+ “” -> this appends an empty string to the host name previously extracted, as explained above.

Why adding an empty text to the host name? This way you can be sure the a variable contains some text, and not an object.
window.location.host is a javascript object, that could be considered as an object if used “as is” or just as a string if you add some text to it.

KeyboardGod
6 years ago

0

[quote=dimooz][/quote]

So if there was no empty string, the b variable (a.length) wouldn’t work?

dimooz
6 years ago | edited 6 years ago

0

It works here in firefox, [s]but not sure it would work in all browser nor in all versions of them[/s].
Yes, it works. But in a general manner, if you need to operate on some text, be sure your var stores a text and nothing else. In example you could encounter same problem with digits, those could be considered as number or as text.

https://www.hackthis.co.uk/forum/level-discussion/javascript-levels/javascript-level-5/solutions/40234-couple-of-questions#latest
alert(window.location.host.length);
-> 18

KeyboardGod
6 years ago

0

I don’t know why such a simple thing (as you put it) is giving me a hard time, I appreciate all the help you gave though thanks man.

So, if I do,

a = window.location.host

Then the output is,

www.hackthis.co.uk

If I wanted to operate on the output of a, I couldn’t because the output is undefined.

But If I add,

a = window.location.host + “”

Then the output will be,

“www.hackthis.co.uk”

and, I can operate on that.

Am I correct?

dimooz
6 years ago

0

You’re absolutely right :)

Discussion thread has been locked. You can no longer add new posts.
1 of 6

This site only uses cookies that are essential for the functionality of this website. Cookies are not used for tracking or marketing purposes.

By using our site, you acknowledge that you have read and understand our Privacy Policy, and Terms of Service.

Dismiss