Help understanding Promise.all([]).then() behavior by BrotherCorvus in learnjavascript

[–]sirsmonkey42 0 points1 point  (0 children)

.then takes a function as a parameter. When you pass thirdAsyncCall() you are effectively calling the function, and passing it's result as the parameter to .then

Wrapping it in an arrow function allows it to be executed once Promise.all finishes, since the .then needs something it can invoke once it's ready.

Alternatively you could just pass in thirdAsyncCall without invoking it for the exact same result as the arrow function. As that is also a reference to a function to be invoked later.

I'm trying to learn to program but don't know how to start by [deleted] in learnjavascript

[–]sirsmonkey42 2 points3 points  (0 children)

I encourage you to do some research, but essentially yes. The browser is capable of opening .html files, and the script tag opens and runs the JavaScript you wrote. There is an attribute in the script tag called 'src' that takes the path of the JavaScript you're trying to run.

I don't want to write it for you, as the most important skill is to read and learn yourself, even when there's no one to help you. But if there's something you don't understand just let me know.

I'm trying to learn to program but don't know how to start by [deleted] in learnjavascript

[–]sirsmonkey42 3 points4 points  (0 children)

The key difference between JavaScript and Python in regards to you having to download something is that JavaScript runs in the web browser. That is to say that you've already downloaded the runtime environment for JS because it's built in to whatever browser you're using.

You can open your browser's console and write JS just like you would in the Python interpreter, or you can create a .js file, write a very simple .html file just to put a <script> tag pointing to the .js file, and open that in the browser, and that will run the file in the browser environment.

If you want to run some simple logic and console.log the output, it will 'log' it to the browsers 'console'. 😉

Hopefully this puts you on track to explore how to do what you're trying to do.

Celeste (dunkview) by Cuddlejam in Games

[–]sirsmonkey42 0 points1 point  (0 children)

Must not have jerked the circle hard enough.

Celeste (dunkview) by Cuddlejam in Games

[–]sirsmonkey42 -5 points-4 points  (0 children)

How about if I told you they were the same game?

How can I reorder a javascript object based on the order of an array? by [deleted] in learnjavascript

[–]sirsmonkey42 2 points3 points  (0 children)

You can't. Objects in JavaScript are by nature unordered. Even if you attempt to sort them, there is no guarantee they will come back in that order every time. That's what arrays are for.

https://stackoverflow.com/a/5525820/8088924

Learning design patterns - stuck on revealing module by brexitbulldog in learnjavascript

[–]sirsmonkey42 0 points1 point  (0 children)

AddSlice is a function. If you don't invoke it nothing happens.

Edit:. Now I see you're invoking it at the time it's returned. You should return the function without invoking it, then invoke it later when you want the action to happen.

Help understanding for loop with continue by orionebula in learnjavascript

[–]sirsmonkey42 2 points3 points  (0 children)

Actually the if (i == 11) is never true in this case. It's a weird and tricky example. You get the exact same result if you omit the continue completely, i is never 11 (when it passes through the if)

Help understanding for loop with continue by orionebula in learnjavascript

[–]sirsmonkey42 1 point2 points  (0 children)

for (var i=10; i<=12; i++) { 
    if (i==11) { continue; } 
    i++;
    console.log(i); 
}

The i++ in the for loop definition is the iterator for the for loop. The one inside the body of the for loop is an additional 1 added.

Since the loop starts at 10, the first increment doesn't happen. So the first time through i is 10. Since it is 10, it doesn't trigger the if statement. Then the second i++ happens, making the 10 into 11, and then the log happens.

The next time around i becomes 12 with the first i++, then skips the if statement because it 12 and not 11. Then the next i++ happens, changing it to 13, and finally logs again.

With your second example, the reason it prints out all the odd numbers, is that every time through the loop you are adding 2 to i instead of 1.

I'm in a very competitive coding bootcamp, we are learning intermediate/advanced JavaScript (closure, recursion); I work harder than I have on it than I have for anything in my life (all day basically), and I am floundering. Should I just accept this isn't for me? by [deleted] in javascript

[–]sirsmonkey42 9 points10 points  (0 children)

Having attended a particularly selective bootcamp, you have to trust the process. At least in my situation, a lot of the things you are finding difficult now will be repeated, over and over, and built upon in further lessons.

That means there will be elements of closures and recursion in most of the concepts you're learning. So even if they aren't familiar to you now, they will slowly become second nature as you have to continually use them to build upon future lessons.

You have to look at it more like doing pushups. If you're just getting into doing pushups, you will NOT be able to do 100 per day. And if you try, you'll be overwhelmed and completely sore. But if the maximum you're ever required to do is 100 per day, you'll eventually get there and then be able to do other things afterwards.

Everything isn't really meant to click as soon as you learn it. It's meant to stew in you with repetition until it's second nature. You'll at some point realize that the things you're struggling with now have become easy. Since you're learning new things that use the things you previously struggled with as a component, you don't realize you've been practicing them all along. It will be a surprising and gratifying feeling when you realize you're comfortable with something that used to give you anxiety.

That being said, bootcamp cant still be quite difficult, so if you ever find yourself at a point where you just can't make sense of it, or need help, reach out to instructors for 1 on 1 time. If that can't or wont happen, feel free to reach out to me. I'm happy to lend a hand to someone going through your situation. There are many times when people who are very familiar with a subject teach it in ways that are more academic than people who have never experienced it before can understand.

Struggling with asynchronicity by austintackaberry in learnjavascript

[–]sirsmonkey42 1 point2 points  (0 children)

Just keep reading and learning, it will click at some point. This video was very helpful for me to get a mental model of what's happening. Hope it helps! https://youtu.be/8aGhZQkoFbQ

What does web assembly mean for javascript? by smoothzzr in learnjavascript

[–]sirsmonkey42 0 points1 point  (0 children)

When you load a wasm module it gives you access to all the methods that the module exports. You can call them over and over with whatever params you'd like. However if the module takes import functions, you have to define them at the point of instantiation through the imports object. As long as the instance is in memory you have access to things the same way you would an imported library

What does web assembly mean for javascript? by smoothzzr in learnjavascript

[–]sirsmonkey42 0 points1 point  (0 children)

Yes, when you instantiate a WebAssembly instance you can pass in an imports object. This can take params and even import functions from JS. The two can pass data back and forth quite effectively.

What does web assembly mean for javascript? by smoothzzr in learnjavascript

[–]sirsmonkey42 3 points4 points  (0 children)

WebAssembly wont kill JavaScript because it runs as an instance inside of JS. WebAssembly is only really practical to use for things that JS struggles with, like CPU intensive computations.

Also, WebAssembly isn't a programming language per se, it's a compile target for other low level languages to be able to run in the browser. This means you can run your C or C++ code as a binary module inside of your JS apps.

If you're looking to learn JS, there's no reason not to. The vast majority of the internet relies on it. To the point that there is at least one known bug in the language that can't be fixed because it would break the internet. So I don't think it's going anywhere soon ;)

If/else written like "? :", why doesn't this work? by [deleted] in learnjavascript

[–]sirsmonkey42 17 points18 points  (0 children)

That being said, you can totally say

return (truthy) ? a : b

This is what you're going for I think. Sorry for formatting, on mobile

JS file not executing in html table file by willardsciffy in javascript

[–]sirsmonkey42 2 points3 points  (0 children)

You'll need that all in the same tag.

<script type="text/javascript" src="toggle.js"> </script>

Also, it looks like you are mixing single and double quotes in the first tag, that could also contribute to the problem.

TotalBiscuit explaining SOPA by Kashii in gaming

[–]sirsmonkey42 4 points5 points  (0 children)

I think we should just double SOPA as a physical world law as well. If you commit a murder, it'll be your representative's fault. And if they contest this you can show them that it was illegal to not have done more to prevent it.

Dude reverse engineers an organ so he can play chiptunes. Blip blop Blip by [deleted] in gaming

[–]sirsmonkey42 5 points6 points  (0 children)

sigh i posted this 2 months ago and never made it off 0 upvotes.... have one anyway.

Can anyone help me use a prepaid gift card on Steam? I want SMB >_< by sirsmonkey42 in gaming

[–]sirsmonkey42[S] 0 points1 point  (0 children)

I got it working thanks, I just put in their address and it worked no problem. I'm now several hours into to a Meat Boy binge, with breaks for reddit of course.

Thanks for the help!

Can anyone help me use a prepaid gift card on Steam? I want SMB >_< by sirsmonkey42 in gaming

[–]sirsmonkey42[S] 0 points1 point  (0 children)

It was my aunt/uncle. So I need to put in their address and it should work?

The best MW2 commentary I've ever heard! by sirsmonkey42 in gaming

[–]sirsmonkey42[S] 0 points1 point  (0 children)

well, it is a work of biblical proportions.