Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    David Castner
    @davidjcastner
    so return does just that is returns a value of a function, so it can be used later on. Let's say you wanted to keep track of the how many wins each player had, then you might return the name of the player from your function (rather than a statement about who won). And then you can call your function multiple times and add a name to some sort of results tracker.
    basically it's so than you can use the results of your function later on
    Jonathan Herman
    @lantech19446
    o ok cool that explains why nothing was showing up on their screen but it still said the code was right even though earlier they kept displaying the returns
    David Castner
    @davidjcastner
    and here's some more javascript fun facts, but NEVER do this:
    var theScope = "outerScope";
    
    var functionThree = function() {
        console.log("running function three:");
        // because of the way the javascript compiler works, you can even set variables before they are declared
        // further down I have a statement `var theScope;`
        // so the function reserves the name theScope before running
        // therefore `theScope` is not referring to the global version
        console.log(theScope); // not the global version, currently undefined
        theScope = "wtf!?!!?!";
        console.log(theScope);
        var theScope; // actually declaring the variable used above (say whaaaaaaa?)
        console.log(theScope); // still "wtf!?!!?!"
        console.log(""); // spacer
        // mind blown
    };
    
    functionThree();
    // global version of `theScope` is still "outerScope"
    console.log(theScope);
    Jonathan Herman
    @lantech19446
    lol I was confused about that when you wrote it out that way above
    David Castner
    @davidjcastner
    yea basically the compiler checks the whole function for declarations before running the code
    Jonathan Herman
    @lantech19446
    just figured out that I could actually do alert (compare(userChoice, computerChoice)); at the end and get closer to what I expected would happen
    I still don't know that I could write any of this on my own but I feel like I'm understanding the stuff more than I was
    David Castner
    @davidjcastner
    that's all that matters, it will take time
    Jonathan Herman
    @lantech19446
    ok one more question, say I write a function somewhere else in the program and I want to rerun it later like the whole shebang any of the prompts alerts etc not just one aspect of it how would I invoke it
    Jonathan Herman
    @lantech19446
    actually I mistated that, it's not a function I want to rerun it's the userChoice variable I want to rerun
    Eric Phy
    @SimplyPhy
    you don’t rerun variables, but you can call the variable or reassign it anytime, so long as its available in the scope where you attempt to call/reassign/‘rerun'
    Jonathan Herman
    @lantech19446
    so I'm creating an if else scenario where if the user selects something that isn't an option it will come up with a popup that says invalid choice that much works but I then want it to take them back to the prompt for making a choice which is tied in directly to the userChoice variable and the proceeding if else statements so I'm not sure beyond else { alert(invalid choice!); } how to make that happen and I don't really have the terminology down well enough to find anything useful on google or SO
    Eric Phy
    @SimplyPhy
    maybe just a straight return; ?
    Jonathan Herman
    @lantech19446
    I need a loop but I'm not clear on how to do it yet so I kept userChoice as a global variable set it equal to "null" and created a function that encompasses the prompt and subsequent if else then calls the function and sets it equal to userChoice the problem I run into is if the user inputs an invalid choice I leave userChoice = "null" and want to use an if else that says if userChoice is null rerun the function that prompts for their choice but it keeps telling me I have a } where I don't need it and I definitely need it there so I'm not sure where I messed up yet. right now i have to run to the bank though. Maybe when I get back I can put it on github so you can see it more easily
    Eric Phy
    @SimplyPhy
    you can probably just post it here inside three `s too
    depending on the line count, i guess
    also, if you tells you there’s an extra }, there probably is an extra } :D
    but maybe not; we’ll see
    Jonathan Herman
    @lantech19446
    var userChoice = "null";
    var choice = function(choice){
        prompt("Do you choose rock, paper or scissors?");
    if (choice === "rock") {
        userChoice = "rock";
    }
        else if (choice === "paper") {
            userChoice = "paper";
        }
        else if (choice === "scissors") {
            userChoice = "scissors";
        }
        else {
                alert("invalid choice!");
                userChoice = "null";
            }
        }
    choice (userChoice);
    if (userChoice === "null") {
        function choice()
    }
    else {
        function compare()
    }
    
    var computerChoice = Math.random();
    if (computerChoice < 0.34) {
        computerChoice = "rock";
    } else if(computerChoice <= 0.67) {
        computerChoice = "paper";
    } else {
        computerChoice = "scissors";
    }
    var compare = function (choice1, choice2) {
        if (choice1 === choice2) {
            return "The result is a tie!";
        }
        else if (choice1 === "rock") {
            if (choice2 === "scissors") {
                return "rock wins";
        }
            else {
                return "paper wins";
            }
        }
            else if (choice1 === "paper") {
                if (choice2 === "rock") {
                    return "paper wins";
                }
                    else {
                        return "scissors wins"
                    }
                }
                else if (choice1 === "scissors") {
                    if (choice2 === "rock") {
                    return "rock wins";
                    }
                    else {
                        return "scissors wins";
                    }
                }
            }
                    alert (compare(userChoice, computerChoice));
    Matt Tarabulski
    @bulski7
    @Lilyheart where is the meetup on tuesday? would like to come check it out
    Lily Romano
    @Lilyheart
    Tuesday? This chat room.
    Matt Tarabulski
    @bulski7
    oh gotcha
    Lily Romano
    @Lilyheart
    And welcome :fireworks:
    Matt Tarabulski
    @bulski7
    i meant the in person
    that is wednesday right?
    Lily Romano
    @Lilyheart
    The next in person is wednesday 1/11. The location should be on meetup. North Wales library
    Matt Tarabulski
    @bulski7
    ok got it I see it now
    Scott
    @TScottM12
    I've been thinking about coming and checking it out as well; just haven't had the chance yet
    Lily Romano
    @Lilyheart
    1/11 is a (hopefully) special (hopefully) big joint meetup with both MontCode and Buxmont Openhacks. Thus the different library.
    Matt Tarabulski
    @bulski7
    ok great, sounds fun
    Lily Romano
    @Lilyheart
    That reminds me…

    @/all For those not on meetup’s MontCode email list, this message went out yesterday: Hello fellow MontCoders! 2016 has been an interesting year for the group! The group officially kicked off May 17th. Since then, we have has 31 weekly online chats, 13 meetups, and 2 lectures! We've posted nearly 14,000 messages in the chat room!

    I am looking for ways to make 2017 even better than 2016. But, to do this I need to know what you want! I’ve created a survey to gather this information. If you could please just take a few minutes of your time it would be greatly appreciated. None of the fields are required and you can skip any fields you wish. However! If you complete every field (but the last one, you'll see it) your name will be entered into a hat. On the January 11th meetup, I will pull for a prize basket! I am still gathering more prizes but at this time we have stickers, an Arduino pro mini, and a gift card!

    Mike
    @dcpking
    @lantech19446 Jonathan, To avoid mismatches like you were running into, try religiously using the parens everywhere ! So "if () { <statements>} else {<statements>} at all times.
    Matt Tarabulski
    @bulski7
    i filled out the survey
    looking forward to meeting people
    Lily Romano
    @Lilyheart
    Thanks! :thumbsup: :thumbsup: :thumbsup:
    Jonathan Herman
    @lantech19446
    @dcpking i have no idea what you're talking about i haven't figured out the issue yet and as far as i can see all my if paramatere are in () are you seeing something I'm not?
    Lily Romano
    @Lilyheart
    How is everyone's holiday? I'm making an arduino kit for the survey prize which is fun because I really have no idea how thing work :laughing: my roommate will (hopefully) fix anything I get wrong xD
    Lily Romano
    @Lilyheart
    @dcpking what do you think? A little kit with an LED that can be programmed to blink to get 'em excited to program with hardware? [for the survey prize bucket]
    Mike
    @dcpking
    Sounds neat, @Lilyheart ! Can you include a microphone, so it blinks more often as the ambient noise increases ? (Sort of a "calm down!!" machine :) )
    @lantech19446 If you're still here, send me your email and I'll show you how I might have laid out your code ...
    Lily Romano
    @Lilyheart
    If they wanna go out and buy one, more power to ‘em xD
    Mike
    @dcpking
    A mic? I'll spot you the cost of one from RadioShack if you like
    Lily Romano
    @Lilyheart
    I’m not sure what all you’d need to hook it into the stuff. It’s this board. Going to see if C will solder some pins on. right now i have my tester mini plugged into a breadboard with a resister and an LED xD
    powered off the ftdi board that is used to program it cuz i’m lazy
    Mike
    @dcpking
    I've never seen c solder anything. Do you mean c++ ? :)
    Lily Romano
    @Lilyheart
    c = my roommate xD
    Mike
    @dcpking
    I guessed you were invoking some sort of a library :)
    Lily Romano
    @Lilyheart
    xD does radio shack do small programming boards like microcenter?