What the heck. This was posted 3 years ago and am now barely seeing it!? This was the most basic, YET thorough explanation on a return
@coding-with-dave4 жыл бұрын
Thanks. That means a lot :)
@SaeleeSaan3 жыл бұрын
seriously.
@dr_corrupt10142 жыл бұрын
@@coding-with-dave bro you explain it best what an amazing explanation
@kira3821 Жыл бұрын
me too, i just started js last month and this was very helpful, im glad ive stumbled on this video, and this was 5 years ago lmao
@ibraheemmudasser4810 Жыл бұрын
And i am seeing this after6 years😂
@rheavictor72 жыл бұрын
This is the one. I have a hard time understanding the "why" for using return, and now I'm starting to get the idea. My job is now to test it so I can conclude things by myself, thank you so much!
@rehanmalik28983 жыл бұрын
A nice simple way to explain the return concept. As a fresher in JS it was very valuable lesson for me. Thanks
@lorenzejay32964 жыл бұрын
After watching many reviews, this was the one for me. I understand it now. Thank you
@coding-with-dave4 жыл бұрын
Thank you Lorenze. I'm so glad it helped.
@k.iskandar3 жыл бұрын
I bought a udemy course and the tutor didn't explain return function particularly well. Your explanation just made it so much easier to understand. Thank you very much. You've earned a subscriber.
@coding-with-dave3 жыл бұрын
Thanks for the kind words.
@krithiksingh2 жыл бұрын
Same problem here, I feel like he explained the return function very poorly.
@aavezshaikh143 Жыл бұрын
Is that course by Angela on udemy ?
@ronkeylinarizini80494 жыл бұрын
I'm pretty much gonna echo what everyone else has been saying; best tutorial I've found yet. Thank you!
@coding-with-dave4 жыл бұрын
Thank you very much for taking them time to say that.
@ulijibkadelm3183 жыл бұрын
I love you bro. I was literally confused after watching so many tutorials about return because they not straight to the point. But now I understand it, Thank you very much. You earn a new subscriber and you deserve more
@coding-with-dave3 жыл бұрын
Appreciate the kind words. I'm glad I could help.
@revanthv13194 жыл бұрын
i dont know why you did not get more subcribers but i understood it very clearly thank you bro
@coding-with-dave4 жыл бұрын
Thanks. I'm happy that it helped.
@ThePickleVR Жыл бұрын
Thank you. I've been looking all over for an answer for this. I just couldn't understand untill watching this.
@coding-with-dave Жыл бұрын
Glad I could be of assistance to you. Keep getting better.
@shahulz47053 жыл бұрын
Crystal clear after 7hours of searching a same concept tanq bro from India:)
@coding-with-dave3 жыл бұрын
Glad it helped. Happy coding :)
@bryallen11Ай бұрын
I managed to get to 2:46 and realized that I knew less about return than I did before.
@bryallen11Ай бұрын
Teaching is an art that some people have and some people don't.
@bryallen11Ай бұрын
Some people are able to make the complex easy and understandable, others are apt to make the easy and understandable very complex.
@DavidHustАй бұрын
hopefully it was helpful. Is there anything that's still unclear that I can help you with?
@yammmaya38382 жыл бұрын
I 've been struggling to undertstand the concept of return. Your explaination was just what I was looking for. Thank you so much!!! You made it super clear!🤩🤩
@coding-with-dave2 жыл бұрын
I'm glad it help. Keep trying to learn one new thing a day. Even if it's small.
@rahxephon764 жыл бұрын
Thank you so much for this video, by far the best explanation I've found on this topic.
@purple7770 Жыл бұрын
I appreciate the way you describe your work! I think this is one of the best beginner friendly channels on youtube!
@coding-with-dave Жыл бұрын
Wow. That's very nice of you to say. Glad it helped.
@tyreesewray919011 ай бұрын
Bro thank you so much, I felt so slow trying to understand the return function. Earned a like and subscribe
@coding-with-dave11 ай бұрын
I know that feeling. Happy that I could help because I know the struggle is real sometimes. Nice job pushing forward through it all. Coding is way more fun when you add to your toolbox of skills.
@mimiraks2 жыл бұрын
Remarkable!! I was stumped that my VS Code couldn’t work with return but now I understand! Mucho gracias
@Bread-vk8fl2 жыл бұрын
So basicly when you use RETURN you must have a variable that storages its value. Now it makes sense for me. Thank you very much!!
@coding-with-dave2 жыл бұрын
That's a good way to think of it. Just to add another level of understanding, technically, you don't need to make a variable because you could write something like `return num * 2`, where num is a parameter that was passed into the function. But you definitely could write the same thing using a variable, `let result = num * 2`, `return result`.
@beesleyrc7594 жыл бұрын
Thanks you! I was having trouble understanding returns. You made it simple to understand.
@khaung4413 Жыл бұрын
I was struggling with retune logic and you got me 100% clear about it
@coding-with-dave Жыл бұрын
Great to hear! Those return functions can be tricky. Keep rockin' it out.
@toppu10animes3 жыл бұрын
Wtf, you're a genius at teaching
@coding-with-dave3 жыл бұрын
Thank you so much. That means a lot. Happy coding.
@millanferende67233 жыл бұрын
I actually like it. It sort of makes sense why this function needs a return. Because otherwise it just gets element by ID, but doesnt DO anything with it. It got it and ok it's done. But RETURN, makes sure that it passes this value back, to be used. function $(X) {return document.getElementById(X)}; BTW, the above function makes sure that if you ever want to get element by ID, all you have to do in your code is write $("anyIdName") and you would have called that function and selected the ID that you want. :) Super useful trick!
@abhishek_23685 Жыл бұрын
Finally understood why and when to use return function. Thanks!
@coding-with-dave Жыл бұрын
Let's goooo. Great to hear. Happy coding!
@Mohammed-od4ju4 жыл бұрын
Thanks! You have been given the ability to teach.
@coding-with-dave4 жыл бұрын
Thanks. That's very nice of you to say.
@VikOtis-Deploys-zl1bz Жыл бұрын
I could follow you the whole way. Thanks for that, always good.
@cilcil27314 жыл бұрын
This was very helpful! I was researching on how return(); works and this answered my questions. Thanks a lot!
@jjcoolman592 жыл бұрын
It took me a minute!! But it finally clicked. I’m really new and js and I think the explanation was amazing!!!
@coding-with-dave2 жыл бұрын
Thanks a lot. I appreciate you taking the time to write that.
@billyjayamunga3 жыл бұрын
I finally filled the gap in my understanding of return. Thank you.
@coding-with-dave3 жыл бұрын
I'm glad I could be a part or that! Happy coding.
@dineshrobins91112 жыл бұрын
That is so simple and neat,,,adds value to our education,,,Thankyou.
@ivanurbina24222 жыл бұрын
Awesome tutorial!!! I appreciated your explanation. This is what I was looking for. I suscribed.
@coding-with-dave2 жыл бұрын
Thanks for giving me feedback. Glad it helped. Happy coding.
@naheeddeedar27923 жыл бұрын
Idid many practice but after watching this video i really happy
@coding-with-dave3 жыл бұрын
Great to hear. I'm glad it helped. Happy coding.
@okolipeace774 Жыл бұрын
Really needed this video. Thanks for explaining it in a simple way
@coding-with-dave Жыл бұрын
Thanks for the feedback. Happy coding.
@BlackZero8803 жыл бұрын
hey thank you man it was like 1+1 explaination to me...you made it cup of cake
@zannatul23 Жыл бұрын
one of the best tutorial on return!
@coding-with-dave Жыл бұрын
Much appreciated. Happy coding.
@rajesh.geesala7565 Жыл бұрын
thank you , you deserve love .. lots of luv from India ❤❤
@coding-with-dave Жыл бұрын
Appreciate the love.
@krithiksingh2 жыл бұрын
I was not understanding the return statement at all but your video made it feel so easy lol, thank you!
@coding-with-dave2 жыл бұрын
That's awesome. Returning values is such an essential skill so great job on persevering and figuring it out.
@krithiksingh2 жыл бұрын
@@coding-with-dave Yessir, ty. Turns out my instructor did a very poor job at explaining its functionality.
@bir.hossan Жыл бұрын
I was struggling with" return concept.Thanks a million for the awesome explanation! 🙌 Your video made it so clear that I finally get 'return' in JavaScript, just like a function returning the value it promised. Keep the great content 'returning'! 😄💻🚀 #CodeWithDave"
@coding-with-dave Жыл бұрын
I see what you did there 😉
@bir.hossan Жыл бұрын
Bro your explanation was so simple and helpful for a beginner like me.@@coding-with-dave
@coding-with-dave Жыл бұрын
@@bir.hossan Thanks for the feedback and kind words. Keep learning, keep coding, make great stuff!
@nicox552 жыл бұрын
dude!! thanks alot i was looking cause i got that function in my class and how my mate explaint it to me was really confusing. now i totaly get it. thanks like and suscribe to your channel mate.
@dnrevan7782 жыл бұрын
Thank you. I understand this better now!!! So pumped
@Kevin_7223 жыл бұрын
man i was confused about what return function meant but after watching this vid I was shocked by how amazinly it was explained and how quickly I understood. Keep it up!
@coding-with-dave2 жыл бұрын
Great to hear. Have fun learning more!
@fredianriko56484 жыл бұрын
for anyone who still confuses, the number he inputs at the prompt window is assigned to the "n1" of the "multiply()" function, so as he put example when he runs the code, the prompt window pop up asking the user to give a number input, he inputs "7" so, the value of "n1" in the "multiply()" function becomes 7, and the sum function is doing its operation which is "+" using the value from the variable that already defined in the first and second line, sum() = 7 multiply() = 6 var product = multiply( 6 , 7 ) console.log(product) the result is = 42 as shown in the video
@papagrey2 жыл бұрын
Man this is way better than skillshare courses I doing, in my opinion they are useless compare to this lesson. Damn, I was trying to understand Return many times and could not get it at all and here after watching few times I totally get it now!! Thank you stranger!
@coding-with-dave2 жыл бұрын
Glad I could help. I usually have to watch a couple videos to really understand a concept. Keep having fun coding!
@papagrey2 жыл бұрын
@@coding-with-dave Thank you very much and I hope you going to keep teaching people coding in the easy way!
@eitanleiberman73342 жыл бұрын
Return was explained very good! Thanks!
@chimsbeatzzedstar Жыл бұрын
Properly explained 🤩
@sina98812 жыл бұрын
Thank you for this really cleared my confusion
@Escko2 жыл бұрын
great clear explanation brother...thank you!!!
@coding-with-dave2 жыл бұрын
You're welcome. Thanks for letting me know it was helpful.
@GovilX3 жыл бұрын
this explanation made perfect sense, thank you.
@coding-with-dave3 жыл бұрын
You're very welcome.
@wellaway3303 Жыл бұрын
this is very comprehensive thank you!
@inactiveaccount48293 жыл бұрын
These are times that I truly wish I had a tutor.. sad. I'm about to watch your video, so I hope this helps, but I'm making my own functions now and I'm struggling to understand when and WHY to put a return statement. I'm putting return statements in the wrong places and it makes me think that my ENTIRE code is messed up, when really I have the return statement within the wrong set of brackets.
@coding-with-dave3 жыл бұрын
Functions that return a value can be tricky for a while. I always think of return statements as being the last thing a function does. That doesn't mean it should be at the bottom, but whenever you are done with a function you could have a return statement. You can also have multiple return statements depending on when and what you want to return. Keep trying and testing things out. You got this!
@AllKindzzzz4 жыл бұрын
Nice explanation, finally made it click for me. Cheers!
@coding-with-dave4 жыл бұрын
I'm glad it helped.
@tuan26862 жыл бұрын
very well explained thank you so much :)
@BusyAsBee17383 жыл бұрын
Hi, amazing video! 3:01 Can u also just plop the add function down as multiply function parameter? I know it's probably not the best practice but I still want to know
@coding-with-dave3 жыл бұрын
Yes, you can. It will just be a bit more difficult to read.
@boladeoluwatobiloba20244 жыл бұрын
Thank you for breaking this down
@coding-with-dave4 жыл бұрын
You're welcome Bolade.
@tofulosophy5 жыл бұрын
nice explanation. So does that mean for a 'return' to be useful, it must always be returned to a variable?
@coding-with-dave5 жыл бұрын
No, but it may be more useful when returned as a variable because you may use that value more than once throughout the rest of your program. For example, if you just want to figure out the largest number in a list of numbers, then returning it, and not assigning it to a variable, is fine; but if you wanted to use that largest number later, then assigning it to a variable would be best.
@tofulosophy5 жыл бұрын
@@coding-with-dave thanks!
@AllKindzzzz4 жыл бұрын
@@coding-with-dave What would returning the largest number even do if you didn't capture the return in a variable? This is the only part of the return I don't quite understand.
@coding-with-dave4 жыл бұрын
@@AllKindzzzz Good question. The answer is... nothing really. I mean the code will still run, but it would be useless code because you would just have a line that would say something like 12; in your main program.
@adolfjamesurian65104 жыл бұрын
My one big question in return statement is what do you mean by return value? Like where will it return and how/where is it restoring the value
@adolfjamesurian65104 жыл бұрын
Hope you noticed this very soon
@coding-with-dave4 жыл бұрын
Returning a value means that the function that's created will do something and the value you want to get FROM that function will be available outside the function. For example, if I make a function called fullName(firstName, lastName) that combines a person's first and last name, I would want to be able to call that function, whenever I want, in my main program and it would always give me (a.k.a. "return") a person's full name. So in this case the function returns a String. To go further with the example, if I called the function fullName("Steve", "Martin") then that would end up being replaced (returned) in my code with the value "Steve Martin". Sorry if this is too wordy. Here is a example that may help. Let me know if it doesn't. codepen.io/dhust/pen/yLOKWdp?editors=0012
@adolfjamesurian65104 жыл бұрын
Ohhhh so return likely means creating a value to return to where its function is called
@coding-with-dave4 жыл бұрын
@@adolfjamesurian6510 Yeppers. You got it!
@ashadcosta87563 жыл бұрын
Why isn't the input considered as a string ? Whenever we take input from the user, using prompt isn't the value always stored as a string, irrespective of a numeric value ?
@coding-with-dave3 жыл бұрын
Great question. That is usually true, like in Python. These two lines of code will out that value is a "number": var value = 4; console.log(typeof value); These two lines of code will print that it's a "string": var value = "4"; console.log(typeof value);
@chibifrank13402 жыл бұрын
I understood finally thanks but when I changed the multiplication to addition sign it just put the two number beside each other without adding it
@coding-with-dave2 жыл бұрын
Can you paste your code here?
@chibifrank13402 жыл бұрын
@@coding-with-dave sure var right = 5 var left = 5 function final ( x,y ){ var add = (x+y); return add; } function pol (a , b){ console.log(a+b); } var add = final (right,left); var input = prompt("Input your age"); pol(add, input);
@coding-with-dave2 жыл бұрын
@@chibifrank1340 Thanks for posting this. The prompt() function gives us (returns) a String. When we use + signs with Strings, all it does is put the two String next to one another, which is what is happening. Since you are already adding 5 and 5, which is 10, and then you input a 4 into the prompt, it will print "10" + "4" which is "104". I should have converted the String into an integer, using parseInt(), and then multiplied the numbers. I added a line and then changed another line. Hope this helps. var right = 5 var left = 5 function final ( x,y ){ var add = (x+y); return add; } function pol (a , b){ console.log(a+b); } var add = final (right,left); var input = prompt("Input your age"); var inputInt = parseInt(input); pol(add, inputInt);
@alejandrocanales51294 жыл бұрын
Great explanation
@Digzaary2 жыл бұрын
i hit like number 1000 thx man
@Quidoute3 жыл бұрын
oh boy, I finally understand this function
@coding-with-dave3 жыл бұрын
Heck yeah! Keep that learning going :)
@scottlaking3 жыл бұрын
Do you have a more elementary version of this topic? At my nube level, I wonder why you chose to use "(n1 , n2) " to "function add". are these just random tags that you chose or are they a part of JS? Why do we need them?
@coding-with-dave3 жыл бұрын
Sorry for the late response. Yes, n1 and n2 are just random names I chose. It could be (num1, num2) or (cat, tree). We need these because I decided that the add function would add two numbers.
@jlambert120132 жыл бұрын
Best explanation.
@SpaceDoodle2008 Жыл бұрын
This helped me so much! 🤗
@coding-with-dave Жыл бұрын
Great to hear. Keep pursuing those skills.
@marwanashraf9036 Жыл бұрын
Thank you very much sir you really helped me alot
@bhp94157 ай бұрын
thanks it helped understand better this return function
@coding-with-dave7 ай бұрын
Glad it helped. Happy coding :)
@GretSeat2 жыл бұрын
I still don't understand what "return" is. This didn't really help. Like... does it just... "hold" a number...? And if so, why don't you just use a variable? why return?
@coding-with-dave2 жыл бұрын
You are right in that the function does have data that it holds. Any calculations that function does, or variables that you create in that function, will only exist while that function's code is running. After the function has completed its last line of code, all that data gets "deleted". So if all that work the function did ends up just being deleted, then what's the point? That's where a return statement can help. If we need to get information from a function back to the main program, like the result of an equation that's being stored in a variable, then we need to return that variable's value by using a return statement. Maybe that helped? If not, let me know.
@ikigu2 жыл бұрын
Thank you! Been struggling to understand what return was.
@coding-with-dave2 жыл бұрын
Glad it helped. Happy coding.
@koraykurtaran57932 жыл бұрын
Thanks! Great explanation!
@assancamara71787 ай бұрын
Tanks a lot the video was so helpful
@stevenberg87193 жыл бұрын
great explanation! THANK YOU!
@coding-with-dave3 жыл бұрын
Thank you for the feedback.
@gallyinamsterdam7273 Жыл бұрын
Thank you for the explanation! One question: you said at 3:57 "we don't always want to print stuff out over the console every time we multiply, all we want it to do is multiply two numbers and give us the value back". What is the difference between "print the number out" and "give us the value back"? In both cases it does the same - gives us 35 in the console.
@gallyinamsterdam7273 Жыл бұрын
Or is it just for this particular example that the outcomes are the same, but the purpose of this extra step is that we could use this "return" in the future? But for now it just gives us the same 35 because that's as far as the current call goes?
@coding-with-dave Жыл бұрын
Printing to the console is usually meant for debugging your code, aka finding out what's going on. Usually, we want to use that number somewhere else in our program. For instance, maybe we have the price for a hamburger and we buy four of them. We can use this function to do that. But then we also need to calculate the taxes on top of that. So we would return the total price of all the hamburgers from the function, then we can take that number, call the same function but this time pass in that total and the tax rate, and then return that new, taxes total. We don't need to print anything to the console but we may want to show that on a webpage so the customer can see it. A little lengthy but I hope that helps. If not, let me know.
@gallyinamsterdam7273 Жыл бұрын
@@coding-with-dave thank you for the explanation! It does help :)
@Pedro-bu8xd Жыл бұрын
Bravo Sir.. thanks a bunch
@coding-with-dave Жыл бұрын
Thanks for letting me know. Happy coding.
@sallylauper82223 жыл бұрын
Don't functions always return some value, even if you don't use return command?
@coding-with-dave3 жыл бұрын
Great question. In JavaScript it may seem like that but that's not the case. You can test this idea using the following code: function add() { var sum = 3 + 4; } console.log(add());
@coding-with-dave3 жыл бұрын
The idea of functions returning or not returning a value makes more sense with a language like Java. When you make a function in Java you actually have to state what type of data you'll return, like a String or int. And if you don't want to return anything you would use the "void" keyword instead.
@matthewblasco47202 жыл бұрын
This made me a hell lot level clearer about returns. Just thanks to you! Based on my understanding after watching this video, this means that the `return` makes the function's result call-able or storable in a variable or container? right? sometime later we can use the whole function again with just the variable name right? coz i tried calling the function without the return and it just says NaN, so I guess it's right? Thank you so much!
@coding-with-dave2 жыл бұрын
"this means that the `return` makes the function's result call-able or storable" - I like this thought. Never thought about it like that, and you are correct. "sometime later we can use the whole function again with just the variable name right?" - I probably wouldn't say that you "use the whole function again". The function has already been ran so it has been replaced by the returned value. That value is now stored in the variable "sum" which can be used later in your program. I like you're thinking with all of this. Keep up the good work!
@dr_corrupt10142 жыл бұрын
best explanation everrr
@coding-with-dave2 жыл бұрын
Appreciated.
@einatpilates4 жыл бұрын
great explanation! thanks!
@shahriarsohan873111 ай бұрын
at last, finally i understood return
@coding-with-dave11 ай бұрын
Great to hear it helped. Returns can be quite the struggle so good job keeping at it. It's so important. Thanks for the feedback.
@shahriarsohan873111 ай бұрын
Can you make a vid explaining the use of double function...i mean using function inside an another function?
@DavidHust11 ай бұрын
@@shahriarsohan8731I like that idea. Seems like a natural progression.
@katherinel6448 Жыл бұрын
thank you this helped so much!
@coding-with-dave Жыл бұрын
Thanks for taking the time to let me know. Good luck with improving those coding skills. It's so much fun.
@EngineeringLife02 жыл бұрын
Great explanation!!!!!
@TheKre8ivemind Жыл бұрын
if your watching this and it doesent make sense come back a day later and pause it from time to time and code this out yourself it will make WAY more sense. i was learning about function, arguments, parameters, and returns in the same day and this seemed like gibberish. let your brain cool off1 ITS ACTUALLY NOT THAT HARD if you give yourself a break.
@coding-with-dave Жыл бұрын
Great suggestion. Sometimes it can be overwhelming the first time. Have fun coding!
@hasansabuz4 жыл бұрын
Allah will sure bless u my brother. This video helped me a lot
@toppu10animes3 жыл бұрын
Nah, Jesus will.
@-detectivealec89374 жыл бұрын
Thanks from 2020 lol, guess I'm starting late with programming
@coding-with-dave4 жыл бұрын
It's never too late to learn a superpower like programming :) Good luck.
@-detectivealec89373 жыл бұрын
@@coding-with-dave truth! I just got my first job as a back end developer. Started from scratch 6 months ago. Thanks again!
@coding-with-dave3 жыл бұрын
@@-detectivealec8937 Heck yeah! Nice job working hard and staying focused. Congrats.
@fariarana45994 жыл бұрын
whaft enviriomen iddid u use fir this vid
@coding-with-dave4 жыл бұрын
codepen.io
@charlesabinaar65632 жыл бұрын
Im very new to JS, will this also work if not why not? multiply(prompt("Enter a number:"),("add" + "multiply"));
@coding-with-dave2 жыл бұрын
This will not work. The multiply function takes two parameters: n1 and n2, which both need to be numbers. The function call that you shared does pass in a number as the first parameters, n1, so long as they type in a number. The second parameter that you're passing in is not a number, it's a String instead. "add" is a String and "multiply" is a String. So your function call actually looks like this: multiply(prompt("Enter a number: "), "addmultiply")
@greenamogus2 жыл бұрын
I pray that you take this susbscription as a token of my gratitude!!!
@coding-with-dave2 жыл бұрын
Much appreciated. Thanks for the sub.
@flamablegas63083 жыл бұрын
Summary: return means it'll take something and allow u to return that something later on
@coding-with-dave3 жыл бұрын
I would say that's sometimes correct. Functions that return a value don't have to "take something" or "pass in" any parameters. For instance, the function takes in a number but returns the value of true or false. It could also not pass in any value and return something. function isLarge(num) { if (num > 100) return true; else return false; } var number = prompt("Enter a number"); console.log(isLarge(number));
@venkatramanan266 Жыл бұрын
thanks for explaining
@jayaditya55132 жыл бұрын
Now i can sleep in peace.
@coding-with-dave2 жыл бұрын
I actually lol'ed. Thanks for that.
@fireball14332 жыл бұрын
Thankss i was struggling to understand return
@coding-with-dave2 жыл бұрын
Glad it helped.
@latinstuff13 жыл бұрын
I am doing the udacity beginner introduction to JavaScript and it can get very fustrating sometimes since they don't seem to explain as well as this, thank you for clarifying this. the only thing that confuses me is how you named the variables outside the function body and they have the names number and another number, instead of N1 and N2. that still confuses me, I guess I have to rewatch this a few times to get it haha
@coding-with-dave3 жыл бұрын
Yeah, that can easily be confusing. "number" and "anotherNumber" are variables that exist in the main part of the program (not in a function). After you pass them into a function they can be renamed, which is what I did. Usually, the parameters of a function have very generic names, like n1 and n2 in this case, so that it can be reused over and over with different values and in different situations. I tend to think of parameters as a list of the variables I can use in my function. So when I passed "number", which has a value of 4, into the function, that's like saying that "n1 = 4" inside the function. Hope that helps.
@latinstuff13 жыл бұрын
@@coding-with-dave it helps a lot thank you so much for this explanation ! I’m starting at Ironhack in March so I’m trying to prepare myself haha
@coding-with-dave3 жыл бұрын
@@latinstuff1 That's exciting. Good luck and have fun!
@latinstuff12 жыл бұрын
@@coding-with-dave :) thank you. This Monday is my first class. I’m ready !
@coding-with-dave2 жыл бұрын
@@latinstuff1 You got this! Have fun and give yourself some grace when things get tough. It's all part of learning.
@momakplayz79853 жыл бұрын
Hi, i still dont know when to use the return function in my code :( Please help
@coding-with-dave3 жыл бұрын
If your main program needs a value, like a number, from your function, then return it. For example, you would like to make a program that determines the total cost (with taxes) of a purchase at a restaurant. In the first part of your program you'll be asking the user for the items they want to purchase. The next part of your program you'll determine the cost of those items. Then you decide to make a function that determines the total cost with tax based on your purchases. The function could pass in two parameters: the cost of the items so far and the tax rate. Your function will multiply those two parameters together and then add it to the cost to get the total cost. Now your main program doesn't know what the result of all the math you did in the function you just made. In order for it to know that you'll need to return that result back to the main program. So maybe you'll write something like: var total_cost = calculate_total_cost(cost, tax_rate) in your main program so that you can store what's being returned from your function in a variable called total_cost. Then the main program can do whatever it needs to do, like print a receipt. I hope that helps a bit. If you write your code like: var total_cost = 3; function calculate_total_cost(cost, tax_rate) { total_cost = 5; } calculate_total_cost(2,1); console.log(total_cost); Then using "return" from the function doesn't matter, since it will output 5, but a number of programming languages don't allow you write that code and have it work.
@abdullah37393 жыл бұрын
very easy to follow thanks
@coding-with-dave3 жыл бұрын
Glad to hear that. Thanks.
@upsidegaming71342 жыл бұрын
at the start, I didn't see the variables at the top so I was so confused when number + anotherNumber equaled 7
@zelenimonter4901 Жыл бұрын
Do I need to convert prompt into a number?
@coding-with-dave Жыл бұрын
Great question. I should have used either parseInt() or parseFloat() since I'm working with numbers.
@ldt89103 жыл бұрын
Thank you so much!!!!!1
@carreraallen83273 жыл бұрын
what compiler do you use bro
@coding-with-dave3 жыл бұрын
Codepen.io
@gabrielm9093 ай бұрын
How does it know n1 is var number...?
@coding-with-dave3 ай бұрын
Great question. It doesn't. I should have forced it to be an integer by using `parseInt()` or `parseFloat()` for a non-whole number. So ultimately, it should have been `parseInt(input('Enter a number: "))`
@gabrielm9093 ай бұрын
From what I’m learning it looks like (n1, n2) are the parameters and (number, anotherNumber) are the arguments.. 🤦🏻♂️ The whole parselnt thing is beyond my scope of what I think I know right now lol..
@mainstagesoundableton62132 жыл бұрын
Awesome, thanks !
@coding-with-dave2 жыл бұрын
You bet. Glad it helped.
@kyleklaiber22252 жыл бұрын
Nice! Thank you!!
@coding-with-dave2 жыл бұрын
For sure!
@SO-fb4ef3 жыл бұрын
So return DOESN'T actually return anything, not by the definition of the word 'return'. Nothing is being returned to where it came from, it is being sent ONE WAY. It appears that 'return' is ACTUALLY more like an assignment operator. 'return' is like an = operator. The = operator's asociativity is 'right to left', but the 'return' operator's asociativity is different, it is 'right to inside the function name'? It is like an = operator which can REMOTELY associate? Am I right? so what is inside the Parameters is unassigned UNDEFINED value, ready to be defined - and what is after the word 'return' is assigned DEFINED value? What is the purpose of the code before the word 'return' then? and the code which comes after the word 'return'.does the code inside { } BEFORE the word 'return' gets ignored when said function is invoked??? Does it not get read or something? why write anything there if it does not get read?? What is the point of the code inside { } before the word 'return'? does the code before 'return', not return? does it turn into an origami paper crane and fly away? what happens to it? Please confirm this with me, I am still confused. I think 'return' is a terrible word for what happens. Am I correct?
@coding-with-dave3 жыл бұрын
It does return a value. It returns it to wherever the function was called. It's only able to assign the value in the function because it was returned. Not sure if that's the part that was confusing. Here is another example I made. (repl.it/@davidhust/return-function) It may not answer all of your questions so let me know if what else is unclear.
@SO-fb4ef3 жыл бұрын
Ahh, thank you. I have not checked your link but I think this was the issue: I was under the impression that the decleration code is essentially copied and brought down for a split second, to be invoked in the position which the 'invoke function line' is written. But the truth is that the decleration code does not shift anywhere at all. What moves if the values in the invoke line parameters, these values are sent UP to the decleration, to assign to the undefined values in the decleration, and THEN are returned back to their original place and THIS is why the function is a reuseable piece of code - because without the return operator then the decleration would simply be updated, and defined by the invoke line of code. Am I right?
@SO-fb4ef3 жыл бұрын
I would also like to say, despite still being confused after watching your video - your video was the clearest explanation I had seen yet, AND I am impressed with your fast reply to my comment. I will subscribe :)
@SO-fb4ef3 жыл бұрын
Ahhh, so the return operator ASSIGNS, THEN RETURNS? Interesting
@coding-with-dave3 жыл бұрын
@@SO-fb4ef The return statement doesn't assign anything. Unless, we have a different definition of assign. It only replaces where the function was called with the value that is returned.
@theerana80428 ай бұрын
I also implement in my VS code but its comes (NaN) was share any solution in the commentes .
@coding-with-dave7 ай бұрын
It might be because the prompt needs to be converted to an integer? Try breaking up line 13 into two separate lines like so: var userInput = parseInt(prompt("Enter a number: ")); var product = multiply(userInput, sum);