JavaScript Function Return Statements

preview_player
Показать описание
Combine the basics of your declared functions with parameters being passed in and return statements sending values back.
Рекомендации по теме
Комментарии
Автор

I like the way you break down your methods.

It really helps me understand this. Please do more videos or even paid course! I’m willing to pay.

Keep it up!

fazzyakamello
Автор

I have never understood functions this deeply until I followed this tutorials. Thank you MILLIONS!

rotrose
Автор

What a brilliant and clear explanation. I've been struggling with the meaning of return all morning. I was writing code that worked by following models but I couldn't really grasp the reasoning. Thank you. SG.

pottingshedgene
Автор

Thank you so much, Steve. I've been using functions and return calls without actually knowing the reason why they were created.

rasulali
Автор

Thanks for these examples. You touched on a couple concepts as well that I added to my understanding.
Thanks for posting.

westcoaster
Автор

Great tutorial. You and All things Javascript are the best

nelsonjimenez
Автор

Thank you soooo much for this playlist Sir.
It has taught me a lot.

zcaptcha
Автор

I love your videos. I start out thinking, "ok, I know this topic, let's have a refresher", then - \t ! Great little bit of info, and it's been like that with all the videos I've binge-watched tonight. Thanks for making them. I hope my likes will get youtube's algorithm to bring you more views.

sashaikevich
Автор

Sweet baby Jesus, this is so interesting but so complex and time consuming. The explanation is so clear though. I`m definitely subscribing and checking other videos. Thank you!

zvladd
Автор

Thanks steve ....you gat a +sub
keep it up !

anwaarkhan
Автор

Thanks Steve!

I have been struggling to wrap my head around all these concepts for days.

for example:
function max(arr){
var max = arr[0];
for(var i = 1; i < arr.length; i++){
if(arr[i] > max){
max = arr[i];
}
}
return max;
}

max([1, 5, 8, 4, 3, 1])

Don't know why it looks so straight forward but I just cant seem to commit it to memory. I keep having to go back and back and back. Ugh!!

GRIFFEN
Автор

you can also use the while loop to develop this program such that the loop ends when the available balance is zero. correct?

patfoiloofficial
Автор

Thanks for another awesome video Steve. Question for you: How would I go about filling the visitCarnival function array from the user input from a simple HTML form?

jeff-creations
Автор

Suppose i return some value based on an if condition inside a forloop will the forloop run until the end or it will terminate after return statement..?

aadil
Автор

That code example can be used as a nice demonstration for function factories. ( function consume_product(price) {...} )

hackerish
Автор

Hello Steve, thanks again for all your help. I'm stuck on something.


function drinkBeer(){
if(checkBalance(beerCost)){
accountBalance = accountBalance - beerCost
console.log("Enjoy your beer.")
}
console.log("\tBalance:", accountBalance.toFixed(2))
}

console.log(drinkBeer())


I get the result indented but in a strange way. Like this:


"Enjoy your beer."
" Balance:" "9.50" I tried to move it the \t around but it inserts more "" . Any guidance appreciated.

DmitriyMalayevProfile
Автор

Steve, could you please tell me where can we find the it's source code, it will be helpful to save some time.

praveens
Автор

Seems that you are making the subtraction twice. Once just to check if greater than zero and then once more to display the balance.
For the sake of refactoring (I know it is far from the scope of this lecture) - could you give me / us a hint. I am thinking of returning object both with boolean value as well as with the balance itself. Or to return just the balance and make the if comparison / decision inside the calling f-n ??

Thank you. Greeting from Bulgaria

mocococo
Автор

Was going to try to contact you privately but can't find a link.
Here is a little food for next video. Perhaps: "Refactoring Code"

Thanks Again for this.

// food price
var beer = 6.25;
var burger = 4.75;
var pop = 3.00;

// money
var balance = 15.75;

function check_balance(amt, item)
{
if(balance - amt >= 0)
{
balance -= amt;
console.log('Enjoy your ' + item);
console.log('\tBalance: $' + balance.toFixed(2));
//return true;
} else
{
console.log('INSUFFICIENT FUNDS');
console.log('\tBalance: $' + balance.toFixed(2));
//return false;
}
}

// drink beer
function drink_beer()
{
check_balance(beer, 'beer')
}

// eat burger
function eat_burger()
{
check_balance(burger, 'burger')
}

// drink pop
function drink_pop()
{
check_balance(pop, 'pop')
}

// visit the carnival
var mealList = [eat_burger, drink_beer, eat_burger, drink_beer];

function visitCarnival(mlist)
{
for(var i = 0; i < mlist.length; i++)
{
mlist[i].call();
}
}

// This does the work to call function and provide list of functions
visitCarnival(mealList);

westcoaster
Автор

Explain this please... i'm seeing "num" but not sure what it's doing...
function welcomeToGators(list) {
for (let i = 0, num = list.length; num < 0; i++) {
list[i]();
}
};

CrazyEddie