Results 1 to 2 of 2
  1. #1
    mariabutenka is offline Member
    Join Date
    Mar 2014
    Posts
    1
    Rep Power
    0

    Unhappy Problems with converting Python to JavaScript

    Well... I am taking Python this semester. Our teacher wants us to convert Python to JavaScript without really explaining how or/and expecting us to be familiar with it already
    I googled lots of thing out but now I am stuck because I don't know what I did wrong, so I can formulate my question correctly;

    Python Program I have is pretty simple - it prompts you to enter your first and last name and end your DNA string, "CAG" repeats are counted by another function and the result is passed to function that identified weather you may have huntington's decease or not.

    <body>
    <p>Enter First Name: <input type="text" size="25" id="firstname" value="">
    <p>Enter Last Name: <input type="text" size="25" id="lastname" value="">
    <p>Enter DNA: <input type="text" size="25" id="DNA" value="" >

    <p><button onclick="alertt(f,l,d,c,p)" style="background-color:pink"><b>PRESS TO FIND OUT RESULT</b></button></p>

    <script>

    var f = document.getElementById('firstname').value;
    console.log(f);
    var l = document.getElementById('lastname').value;
    console.log(l);
    var d = document.getElementById('DNA').value;// DNA string
    console.log(d);
    var c = countCAG(d); // number of CAG repeats
    console.log(c);
    var p = prediction(c); //prediction
    console.log(p);

    function alertt(f,l,d,c,p)
    {
    alert ("First Name: " +f+ "Last Name: "+l+"DNA string"+d+"NUmber of repeats"+c+"Prediction"+p)
    }


    function countCAG(dna)
    {
    var index = 0;
    var index_2 = 3;
    var count = 0;
    while (index < dna.length)
    {
    if (dna.slice(index,index_2) == "CAG")
    {
    count+=1;
    }
    else
    {
    //break;
    index+=3;
    index_2+=3;
    }
    return count;
    }
    }

    function prediction(numCAG)
    {
    if (numCAG < 28)
    {
    return "Normal, Unaffected";
    }
    else if (36 >= numCAG >= 28)
    {
    return "Intermediate, Unaffected";
    }
    else if (42 >= numCAG >= 37)
    {
    return "Reduced Penetrance, Affected";
    }
    else if (numCAG > 42)
    {
    return "Full Penetrance, Affected";
    }
    else
    {
    return "invalid Count";
    }
    }
    </script>

    </body>
    When I run it there is an issue with countCAG and prediction functions :( I would run each one individually in JS console and I get Undefined, or InvalidString I read that I am supposed to use var in front of each variable, unlike in Python where you just assign variable a value without any add-ons in the front. But JS console seems to recognize both ways of assigning, however var smth=0 immediately evaluates to Undefined, and smth=0, gives me 0... As I said, I am so new to this, and all the basics I learned, I got from online pls don't make fun of me!
    SOMEONE PLS HELP, just point out what am I missing

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,534
    Rep Power
    5

    Default Re: Problems with converting Python to JavaScript

    This is a Java forum, not a JavaScript forum.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

Similar Threads

  1. Replies: 2
    Last Post: 12-08-2012, 04:32 AM
  2. Python IDEs
    By kkid in forum Other IDEs
    Replies: 0
    Last Post: 11-08-2012, 05:01 PM
  3. Java vs. Python
    By bob 6 in forum Forum Lobby
    Replies: 3
    Last Post: 09-10-2012, 11:37 AM
  4. Replies: 0
    Last Post: 12-10-2010, 04:55 AM
  5. Python API
    By sixstring in forum New To Java
    Replies: 0
    Last Post: 10-21-2008, 08:27 PM

Posting Permissions

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