Page 1 of 2 1 2 LastLast
Results 1 to 10 of 12

Thread: Javascripting

  1. #1
    Not Actually Banned Yet Bulletzone's Avatar
    Join Date
    Apr 2015
    Location
    United Kingdom
    Posts
    2,849

    Javascripting

    Hello People, I am taking a JavaScript course and I'm in quite a pickle.
    I'm doing it via code academy and well there appears to be a syntax error which I can not seem to work out.
    If this thread is in the wrong area, then would a moderator kindly move it to where it should be.


    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";
    } console.log("Computer: " + computerChoice);
    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";
    }};


    The main code which you should focus on, is the code in bold. The rest of the code is correct however when I try to run it all together, apparently "there is a syntax error". PLEASE HELP



    P.s. I am making a rock, paper, scissors GAME
    "A fool thinks they know everything but a wise person knows there's something to learn from everyone"
    -
    "Great leaders don't complain about the tools they are given. They work to sharpen them"

  2. #2
    idk what this is
    Join Date
    Nov 2013
    Location
    Heaven
    Posts
    2,948
    I need to take a look at this. It would be better putting them in PHP quotes.

  3. #3
    Not Actually Banned Yet Bulletzone's Avatar
    Join Date
    Apr 2015
    Location
    United Kingdom
    Posts
    2,849
    Quote Originally Posted by Grandpa Illusions View Post
    I need to take a look at this. It would be better putting them in PHP quotes.
    Oh sorry, just really busy and I didn't consider doing that.
    The code is not finished, I am doing it in chunks.
    "A fool thinks they know everything but a wise person knows there's something to learn from everyone"
    -
    "Great leaders don't complain about the tools they are given. They work to sharpen them"

  4. #4
    idk what this is
    Join Date
    Nov 2013
    Location
    Heaven
    Posts
    2,948
    Quote Originally Posted by Bulltzone View Post
    Oh sorry, just really busy and I didn't consider doing that.
    The code is not finished, I am doing it in chunks.
    I'm looking at it. Want to learn GS2 together?

  5. #5
    I would have to try this on codecademy to figure out what's wrong, what section?
    IGN - Daniiel
    Contact on forums, email, or in game for assistance

  6. #6
    Not Actually Banned Yet Bulletzone's Avatar
    Join Date
    Apr 2015
    Location
    United Kingdom
    Posts
    2,849
    Heres the link: Section 7;What if Choice1 was paper?

    https://www.codecademy.com/courses/j...urriculum_id=#

    - - - Updated - - -

    Quote Originally Posted by Grandpa Illusions View Post
    I'm looking at it. Want to learn GS2 together?
    Yeah sure why not?
    "A fool thinks they know everything but a wise person knows there's something to learn from everyone"
    -
    "Great leaders don't complain about the tools they are given. They work to sharpen them"

  7. #7
    Newcomer Patrobot's Avatar
    Join Date
    Oct 2015
    Location
    Australia
    Posts
    13
    PHP Code:
    #Corrected By Patrobot
    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";
    console.log("Computer: " computerChoice);
    var 
    compare=function (choice1choice2) {
     if (
    choice1 === choice2){
    return
    "The result is a tie!";
     }
    else if (
    choice1 === "rock") {

        if(
    choice2 === "scissors") {
            return 
    "rock wins";
        }
        else {
            return 
    "paper wins";
        }
    [
    B]else if (choice1 === "paper") {

     if(
    choice2 === "rock") {
         return 
    "paper wins";
     }
     else {
        return 
    "scissors wins";
     }};
     [/
    B

  8. #8
    Not Actually Banned Yet Bulletzone's Avatar
    Join Date
    Apr 2015
    Location
    United Kingdom
    Posts
    2,849
    Quote Originally Posted by Patrobot View Post
    PHP Code:
    #Corrected By Patrobot
    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";
    console.log("Computer: " computerChoice);
    var 
    compare=function (choice1choice2) {
     if (
    choice1 === choice2){
    return
    "The result is a tie!";
     }
    else if (
    choice1 === "rock") {

        if(
    choice2 === "scissors") {
            return 
    "rock wins";
        }
        else {
            return 
    "paper wins";
        }
    [
    B]else if (choice1 === "paper") {

     if(
    choice2 === "rock") {
         return 
    "paper wins";
     }
     else {
        return 
    "scissors wins";
     }};
     [/
    B
    Apparently their is a problem with my syntax.
    "A fool thinks they know everything but a wise person knows there's something to learn from everyone"
    -
    "Great leaders don't complain about the tools they are given. They work to sharpen them"

  9. #9
    Veteran Jahola's Avatar
    Join Date
    Jun 2013
    Location
    London, England
    Posts
    442
    Fixed your code, have fun!
    PHP Code:
    var compare;
    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";
    }
    console.log("Computer: " computerChoice);
    compare = function (choice1choice2) {
        if (
    choice1 === choice2) {
            return 
    "The result is a tie!";
        } else 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";
        }
    }; 
    - - - Updated - - -

    Let me know if you have any other issues.
    PM me in-game or message me here if you have any issues or enquiries.
    Contact Email:[email protected]


    Learning C#


  10. #10
    Veteran siclesleon's Avatar
    Join Date
    Feb 2015
    Location
    Holland , Leeuwarden
    Posts
    184
    looking at scripts makes me happy
    im still a try hard en fail alot but ...
    every fail is a new learning right ..... ?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •