The Student Room Group

Newbie Coders Chat

Scroll to see replies

Reply 320
Original post by BobBobson
This stuff isn't original to JS btw. C++ (and pretty much any other modern language) can have anonymous functions and function variables but without the god awful JS syntax. JS is only good for one thing and that's for using jQuery on HTML, apart from that, I ****ing hate it.


Haha don't get me started. Notice how crag was already accidently doing weird stuff like passing numeric values as strings, doing math with it and getting away with it due to JS's dynamic typing and automagic type conversions.
Original post by 571122
Let me see if I properly understand what you are asking.

cost is just the argument that belongs to the named function with name orangeCost. The variable orangeCost now points to an area in memory that represents a function.
At the last line, you are calling the [pre]orangeCost("5":wink:;[/pre] function, passing in the literal string "5" as a parameter because that is a statement (a statement ends with a semicolon). A result of that statement is that the function gets looked up in memory and executed (argument + function body, what's inside the braces) with the parameters that you gave it.
So, cost is a placeholder, that sits there, waiting for a value to be assigned to it. When you call [pre]orangeCost("5":wink:;[/pre] you pass in the value 5 and that will be passed onto cost, so that cost now equals 5.
Finally, it will read: console.log(5*5); which will be 25 as a result.
Using the function name makes the Javascript engine look up that function in memory (RAM). Using the parentheses is a way to pass in parameters, so that if they get used, their values will be redirected and assigned to the function's argument definition. Somewhere in memory there is a place for functions and somewhere in there is a place for the function's arguments too.

I hope this was a decent explanation. If not, feel free to inquiry me further on it.

P.S.: it's not good practice to pass in a string where a number is expected, so "5" should be 5.
P.P.S: I'm not a Javascript expert.

in-depth discussion:

Spoiler



:banghead: I wrote a long reply, and then when I hit 'submit' it vanished :motz:

Ok so yeh I think you got what I meant. Part of the problem is that the damn tutorial hasn't bothered to clarify what 'statement', 'argument', etc. are. On my own, 'statement' and 'argument' sound like similar things, so I expect them to do the same things and get confused. It's the same with 'variable', and what you described as a placeholder. In my mind, if 'cost' is a placeholder, it's like a variable... it will change depending on the context while other things are fixed. So it makes me really confused as to which one I'm supposed to 'call'. Perhaps part of the confusion comes from having recently finished with CSS, where defining the value of ID or class is very direct. This seems indirect by contrast.

So after reading your explanation, I am now trying to see the variable + the bit that tells it that it's a function + the content (argument?) of that function as acting all of a piece when I call the variable. Before I was expecting the function to be directly accessible without the variable bit :o: Your bit in the spoiler is helpful... thinking of it as a pointer, rather than as the function itself.

Sorry for the slow reply, btw. I have a bit of time every day to glower at Codecademy and try and make stuff work, but this is on the side of a lot of other responsibilities.

Also thanks @INTit
(edited 7 years ago)
Original post by Craghyrax
:banghead: I wrote a long reply, and then when I hit 'submit' it vanished :motz:

Ok so yeh I think you got what I meant. Part of the problem is that the damn tutorial hasn't bothered to clarify what 'statement', 'argument', etc. are. On my own, 'statement' and 'argument' sound like similar things, so I expect them to do the same things and get confused. It's the same with 'variable', and what you described as a placeholder. In my mind, if 'cost' is a placeholder, it's like a variable... it will change depending on the context while other things are fixed. So it makes me really confused as to which one I'm supposed to 'call'. Perhaps part of the confusion comes from having recently finished with CSS, where defining the value of ID or class is very direct. This seems indirect by contrast.

So after reading your explanation, I am now trying to see the variable + the bit that tells it that it's a function + the content (argument?) of that function as acting all of a piece when I call the variable. Before I was expecting the function to be directly accessible without the variable bit :o: Your bit in the spoiler is helpful... thinking of it as a pointer, rather than as the function itself.

Sorry for the slow reply, btw. I have a bit of time every day to glower at Codecademy and try and make stuff work, but this is on the side of a lot of other responsibilities.

Also thanks @INTit

Hey there Craghyrax, I'm glad to see you are making progress in understanding.

As for the whole statement, expression, variable terminology, this should help.

The explanation for variable is quite simple: it is a piece of information whose value can vary (much like in math, x is a variable, as it represents an arbitrary value).
It is a piece of information that refers to a specific spot in memory (RAM), in such a way that if I were to refer to that memory address, I would find its corresponding value for the variable (e.g.: x = 5). A little basket with an egg in it, if you will.
Original post by 571122
Hey there Craghyrax, I'm glad to see you are making progress in understanding.

As for the whole statement, expression, variable terminology, this should help.

The explanation for variable is quite simple: it is a piece of information whose value can vary (much like in math, x is a variable, as it represents an arbitrary value).
It is a piece of information that refers to a specific spot in memory (RAM), in such a way that if I were to refer to that memory address, I would find its corresponding value for the variable (e.g.: x = 5). A little basket with an egg in it, if you will.

Thanks Five. The link is useful :yy:

Yeh, nevermind...


Oh dear God...
I'd put "shuteye" rather than "shut eye" :lol:
You either laugh or you cry...
(edited 7 years ago)
Ok yeh so this is a good example...
I've switched from Codecademy to Free Code Camp for learning JavaScript.

Three lessons in and Code Camp has informed me that assignations to variables run from right to left!!!!!
If Codecademy had bothered to tell me that, I would probably not have had the confusion I did the other day! :hmpf:
(edited 7 years ago)
Original post by BobBobson
JS is only good for one thing and that's for using jQuery on HTML, apart from that, I ****ing hate it.

The bootcamp I'm interested in seem to want me to learn it without Bootstrap or jQuery. Surely understanding it thoroughly is good for being an advanced web developer?
Original post by Craghyrax
Ok yeh so this is a good example...
I've switched from Codecademy to Free Code Camp for learning JavaScript.

Three lessons in and Code Camp has informed me that assignations to variables run from right to left!!!!!
If Codecademy had bothered to tell me that, I would probably not have had the confusion I did the other day! :hmpf:

This is why I recommend for beginners to read an entire in-depth book on the language, like I did. :redface:
Original post by Craghyrax
The bootcamp I'm interested in seem to want me to learn it without Bootstrap or jQuery. Surely understanding it thoroughly is good for being an advanced web developer?

Bootstrap is just a fancy CSS library to make up for CSS design/problems and you don't need it to understand Javascript.
jQuery is another layer above Javascript to make everything easier and less raw.

I recommend knowing Javascript well (or at least have a good foundation) before going into jQuery. :smile:

As for your question: understanding the design principles of Bootstrap and how it helps CSS problems is helpful to become an advanced web developer, as well as knowing jQuery to a good degree, but I am still of the opinion that it's more important to know the lower level languages (like Javascript) first. It's not a one-off thing, you actually need to have strong fundamentals in the core of it all (in this case CSS for Bootstrap and Javascript for jQuery) in order to understand the bigger picture (Bootstrap and jQuery).

I've worked with two guys who hadn't learned CSS or Javascript decently before and they were struggling like mad to get CSS and jQuery figured out. Every time, I had to go over and tell them how the specific problem they were having would originate back to the way JS and CSS work internally.

And so, I emphasize again, the following skills will make you an advanced web developer:
- have all the basics down (Javascript, HTML5, CSS3) as well as know the history and how the languages evolved, know how they play in today's IT market, etc.
- strong fundamentals and a deep understanding of computer languages
- strong analytical skills to read in between the lines, to see the links between different languages (this helps a lot for debugging. Especially cross-tier, cross-layer debugging and optimization is exceptionally hard)
- dedication, motivation, hunger for knowledge
- studying the languages up to a point that you get super nerdy (past the point people don't care, going into extreme detail and being pedantic, I actually do that, but perhaps that's just my style)
(edited 7 years ago)
Original post by 571122
This is why I recommend for beginners to read an entire in-depth book on the language, like I did. :redface:

Fair enough. That is often the best way to do everything in life. I always got a bit miffed with my undergrads when they complained that the course was hard and never bothered to do the reading that went with it :dry: Well I find the little practical tasks on these courses quite helpful, and all the encouraging badges and stuff. But probably when I finish them I'll also turn to some wider reading on the language. Friends have given me a few resources and lectures to watch :yy:
Original post by 571122
Bootstrap is just a fancy CSS library to make up for CSS design/problems and you don't need it to understand Javascript.
jQuery is another layer above Javascript to make everything easier and less raw.

I recommend knowing Javascript well (or at least have a good foundation) before going into jQuery. :smile:

Codecademy, Free Code Camp and others all teach you bootstrap and JQuery before JavaScript :hmpf: I've skipped those bits because I was warned.
Original post by 571122
Bootstrap is just a fancy CSS library to make up for CSS design/problems and you don't need it to understand Javascript.
jQuery is another layer above Javascript to make everything easier and less raw.

I recommend knowing Javascript well (or at least have a good foundation) before going into jQuery. :smile:

As for your question: understanding the design principles of Bootstrap and how it helps CSS problems is helpful to become an advanced web developer, as well as knowing jQuery to a good degree, but I am still of the opinion that it's more important to know the lower level languages (like Javascript) first. It's not a one-off thing, you actually need to have strong fundamentals in the core of it all (in this case CSS for Bootstrap and Javascript for jQuery) in order to understand the bigger picture (Bootstrap and jQuery).

I've worked with two guys who hadn't learned CSS or Javascript decently before and they were struggling like mad to get CSS and jQuery figured out. Every time, I had to go over and tell them how the specific problem they were having would originate back to the way JS and CSS work internally.

And so, I emphasize again, the following skills will make you an advanced web developer:
- have all the basics down (Javascript, HTML5, CSS3) as well as know the history and how the languages evolved, know how they play in today's IT market, etc.
- strong fundamentals and a deep understanding of computer languages
- strong analytical skills to read in between the lines, to see the links between different languages (this helps a lot for debugging. Especially cross-tier, cross-layer debugging and optimization is exceptionally hard)
- dedication, motivation, hunger for knowledge
- studying the languages up to a point that you get super nerdy (past the point people don't care, going into extreme detail and being pedantic, I actually do that, but perhaps that's just my style)


Hi my good friend. Here are the latest programs i would greatly appreciate your help with:

leapyearsv1.jpg

http://pastebin.com/9QWb1duP

http://pastebin.com/Nm5wdZpF

Thanks!
Original post by john2054
Hi my good friend. Here are the latest programs i would greatly appreciate your help with:

leapyearsv1.jpg

http://pastebin.com/9QWb1duP

http://pastebin.com/Nm5wdZpF

Thanks!


First thing is that the question was asking you to create a static method in the LeapYear class that takes an int and returns a boolean. You're overcomplicating it by have constructors, instance variables etc. All you need is that one static method, and main which should call it a few times..
Original post by BobBobson
First thing is that the question was asking you to create a static method in the LeapYear class that takes an int and returns a boolean. You're overcomplicating it by have constructors, instance variables etc. All you need is that one static method, and main which should call it a few times..


http://pastebin.com/4UYWgDAZ

Is this one any better??
Original post by BobBobson
First thing is that the question was asking you to create a static method in the LeapYear class that takes an int and returns a boolean. You're overcomplicating it by have constructors, instance variables etc. All you need is that one static method, and main which should call it a few times..


Can you show me, at least some of the code, i need for this? I don't know how to do what you have told me Bob?!
Original post by john2054
Hi my good friend. Here are the latest programs i would greatly appreciate your help with:

leapyearsv1.jpg

http://pastebin.com/9QWb1duP

http://pastebin.com/Nm5wdZpF

Thanks!


bool isleap(int year)
{
return year % 4 == 0 && year % 100 || year % 400 == 0;
}
(edited 7 years ago)
Original post by john2054
Hi my good friend. Here are the latest programs i would greatly appreciate your help with:

leapyearsv1.jpg

http://pastebin.com/9QWb1duP

http://pastebin.com/Nm5wdZpF

Thanks!

http://pastebin.com/D5nVgcQK
You're welcome!
Original post by john2054
http://pastebin.com/4UYWgDAZ

Is this one any better??


Yeah that's better, but I would put that if statement within its own boolean method - boolean isLeapYear(), just to keep main as clean as possible, so it will be like:static boolean isLeapYear (int year){
if (...)
return ...;
else
return ...;
}
and then in main, after receiving the year from the user you could have something like:public static void main (String[] args) {
if (isLeapYear(year))
...
else
...
}
Also, I'm not sure whether it's pastebin, but the whitespace seems very off and it's making things hard to follow.


Original post by BobBobson
Yeah that's better, but I would put that if statement within its own boolean method - boolean isLeapYear(), just to keep main as clean as possible, so it will be like:static boolean isLeapYear (int year){
if (...)
return ...;
else
return ...;
}
and then in main, after receiving the year from the user you could have something like:public static void main (String[] args) {
if (isLeapYear(year))
...
else
...
}
Also, I'm not sure whether it's pastebin, but the whitespace seems very off and it's making things hard to follow.


Thanks guys, i have now passed the course, thank hell!
Does anyone here know which websites/books I can use to practice Java? From scratch ideally... thank you.

Posted from TSR Mobile
Original post by Enginerd.
Does anyone here know which websites/books I can use to practice Java? From scratch ideally... thank you.

Posted from TSR Mobile


http://www.headfirstlabs.com/books/hfjava/

Quick Reply

Latest

Trending

Trending