Coding help?

Discussion in 'Miscellaneous' started by golddigger221, Jun 5, 2014.

?

Do you like coding?

CODE 8 vote(s) 50.0%
Huh? 2 vote(s) 12.5%
can't believe you asked this! 4 vote(s) 25.0%
Definetly! 7 vote(s) 43.8%
Nope. 3 vote(s) 18.8%
Hmm, may try it out 4 vote(s) 25.0%
Multiple votes are allowed.
  1. I need help making a javascript Rock Paper Scissors game, can anybody tell me how to do this? The instructions for what I'm supposed to be doing are down below


    If computerChoice is between 0 and 0.33, make computerChoice equal to "rock".
    If computerChoice is between 0.34 and 0.66, make computerChoice equal to "paper".
    If computerChoice is between 0.67 and 1, make computerChoice equal to "scissors"


    Under your existing code, write out the if / else if / else statement.
    In the respective code blocks, change the value of computerChoice based on the rules stated above.
  2. If i were you, i wouldnt use javascript. That is basically just for web elements (atleast thats what i use it for). Try C#

    Anyhoo, I will try er out!
  3. Well, I'm learning websites... Soo....
    technologygeek likes this.
  4. This is a basic little thing, possibly not quite what you wanted.

    Code:
    var computerChoice;
    var returnVar;
    
    if(computerChoice <= 0.33) {
        returnVar = "rock";
    } else if(computerChoice <= 0.66 && computerChoice >= 0.34) {
        returnVar = "paper";
    } else(computerChoice >= 0.67) {
        ReturnVar = "scissors";
    }
    
    I wrote this up quickly on an iPad, so I wouldn't trust it to work.
    technologygeek likes this.
  5. As a tip, I suggest making the random number generator give Integer values ranging from 0 to 3. That way you are working only with 0, 1, and 2 as possible outcomes (because it won't choose 3, just like 0 to 1 will choose at most 0.99 instead of 1). That way you can make it "If computerchoice = 0 then rock", "If computerchoice = 1 then paper", etc.
    Of course the Then statements can be built on further, whether or not you want to keep a running score or display the results of the random number helps determine.
  6. No idea what integer is though :/
  7. Well, I forgot... I have a prewritten code, so that didn't work. This is the code that I need to add on to:
    Code:
     
    var userChoice = prompt("do you choose rock, paper or scissors?")‌
    var computerChoice = Math.random()‌
    console.log(computerChoice)‌
    ‌
  8. I don't do Javascript much, but the typical method in code is to put an Int( ) with the random number generator between the parentheses. Of course then you would have to set the scope for the generator. For as much as I can help here, working with the default 0 to 0.99 might be the best option for now.
  9. *facepalm*

    OH I GET IT NOW!!!:oops::oops::oops:
  10. This should work a bit more like you want. Like Luckygreenbird, I'm not that into scripting languages, so this might be a bit more Java like.
    Code:
    var userChoice = prompt("do you choose rock, paper or scissors?")‌
    var computerChoice = Math.random()‌
    
    if(computerChoice <= 0.33) {
        console.log("rock")‌
    } else if(computerChoice <= 0.66 && computerChoice >= 0.34) {
        console.log("paper")‌
    } else(computerChoice >= 0.67) {
        console.log("scissors")‌
    }
    
  11. welcome to codecademy my friend.

    Code:
    var userChoice = prompt("Do you choose rock, paper or scissors?");
    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!"
        } if (choice1 === "rock"){
            if (choice2 === "scissors") {
                return "rock wins"}
            else {
                return "paper wins"}
        if (choice1 === "paper"){
            if (choice2 === "rock"){
                return "paper wins"}
            else {
                return "scissors wins"}
        if (choice1 === "scissors"){
            if (choice2 === "rock"){
                return "rock wins"}
            else {
                return "scissors wins"}
        }}}}
  12. Bug: .661 :)

    JS is actually now a primary development language now thanks to Node.JS, and is one of my favourite languages. I was heavily into Node before I started Minecraft (See my GitHub), and aiming to get back into it once ES6/Harmony lands in production releases.

    I was working on an online game that was going to be a JS Backend Server, JS Database interface (MongoDB), with JS HTML Template Engine (My own engine I created called Nova, that I even use at my day job for something in production to render Email Templates!), and a JS Client.

    JS is a powerful language, and most of the negativity you will find on JavaScript is not the language itself, but the DOM bindings (JS modifying the DOM for web pages, and the inconsistency between versions).

    Then the next big negative is how simple it is to end up in a mess of code, but if someone writes with proper design using modern design patterns and features such as Promises and Generators, and good code organization, then it is possible to develop large applications in pure JS.
    mba2012 likes this.
  13. EDIT: :oops: fail here lol:

    I MEANT:

    JS was my first language but i never really figured it out :confused:
  14. It's a difficult first language as even experienced developers have a hard time understanding Async development.

    Most dev goes line 1, line 2, line 3, line 4.... but JS starts doing line 1, line 32, line 4, line 56, line 5, line 3, line 1300, line 22... and trying to explain how that is to people is just difficult.
    technologygeek likes this.
  15. JS makes me sad :oops:
  16. Guess what?
    I'm doing this on codecademy :p
  17. If you didn't know what an integer is, it's simply an positive or negative number without any decimal places, including zero(0) The number in you're username is an example of an integer.

    Summarized definition: whole numbers (numbers > 0 without a decimal place) and their opposites
    mba2012 likes this.