www.webdeveloper.com
Results 1 to 5 of 5

Thread: help with code

Hybrid View

  1. #1
    Join Date
    Sep 2012
    Posts
    5

    help with code

    i need help
    i am making a program that conjugates spanish words
    this is only the beginning part that determines what the last two letters is(those are important)
    when i put only the "if" part it works fine
    but when i puts the "else if" and "else" parts in it doesn't work

    var pronoun = prompt("What is your pronoun(put yo, tu, el, etc.)");
    var verb = prompt("What is your verb");
    if (verb.length === 2) {
    var last = verb.substring(0,2);
    };
    else if (verb.length === 3) {
    var last = verb.substring(1,3);
    };
    else if (verb.length === 4) {
    var last = verb.substring(2,4);
    };
    else if (verb.length === 5) {
    var last = verb.substring(3,5);
    };
    else if (verb.length === 6) {
    var last = verb.substring(4,6);
    };
    else if (verb.length === 7) {
    var last = verb.substring(5,7);
    };
    else if (verb.length === 8) {
    var last = verb.substring(6,8);
    };
    else if (verb.length === 9) {
    var last = verb.substring(7,19);
    };
    else if (verb.length === 10) {
    var last = verb.substring(8,10);
    };
    else if (verb.length === 11) {
    var last = verb.substring(9,11);
    };
    else if (verb.length === 12) {
    var last = verb.substring(10,12);
    };
    else if (verb.length === 13) {
    var last = verb.substring(11,13);
    };
    else if (verb.length === 14) {
    var last = verb.substring(12,14);
    };
    else (verb.length === 15) {
    var last = verb.substring(13,15);
    };
    alert(last)

  2. #2
    Join Date
    Mar 2009
    Posts
    452
    there is syntax error in your code.
    remove ; after each }

  3. #3
    Join Date
    Sep 2012
    Posts
    5
    I removed the ;s
    but it still doesn't work
    are them any more bugs?



    var pronoun = prompt("What is your pronoun(put yo, tu, el, etc.)");

    var verb = prompt("What is your verb");

    if (verb.length === 2) {

    var last = verb.substring(0,2);

    }

    else if (verb.length === 3) {

    var last = verb.substring(1,3);

    }

    else if (verb.length === 4) {

    var last = verb.substring(2,4);

    }

    else if (verb.length === 5) {

    var last = verb.substring(3,5);

    }

    else if (verb.length === 6) {

    var last = verb.substring(4,6);

    }

    else if (verb.length === 7) {

    var last = verb.substring(5,7);

    }

    else if (verb.length === 8) {

    var last = verb.substring(6,8);

    }

    else if (verb.length === 9) {

    var last = verb.substring(7,19);

    }

    else if (verb.length === 10) {

    var last = verb.substring(8,10);

    }

    else if (verb.length === 11) {

    var last = verb.substring(9,11);

    }

    else if (verb.length === 12) {

    var last = verb.substring(10,12);

    }

    else if (verb.length === 13) {

    var last = verb.substring(11,13);

    }

    else if (verb.length === 14) {

    var last = verb.substring(12,14);

    }

    else (verb.length === 15) {

    var last = verb.substring(13,15);

    }

    alert(last)

  4. #4
    Join Date
    Sep 2012
    Posts
    5
    on the last else it says missing ; before statement
    what does that mean

  5. #5
    Join Date
    Nov 2010
    Posts
    1,036
    it can either be
    Code:
    else if (verb.length === 15) {
    var last = verb.substring(13,15);
    }
    or just
    Code:
    else {
    var last = verb.substring(13,15);
    }
    an else without an if is like the default - if nothing else matches, the code goes with that one.

    By the way, being that you only want the last two letters of the infinitive, why not avoid all the if elses and just do
    Code:
    var last=verb.substring(verb.length-2)
    Last edited by xelawho; 09-20-2012 at 11:17 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles