Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Lv 2318 points

Shannyhaha

Favorite Answers15%
Answers34
  • Enqueue function in Javascript?

    Use Enqueue()

    Input: document.queue.entry.value (user entry from form text box - don't declare this)

    Computation: back++; myqueue[back] = document.queue.entry.value;

    This is the beginning of my code....any help with the next part which is enqueue()

    <html>

    <head>

    <title>COP2500 - Lab 9</title>

    </style></head>

    <body>

    <center>

    <h3><b>COP2500 Assignment 9</b></h3>

    <b>Queue:</b>

    <form name="queue">

    <input type=text size=60 name="display"><br>

    <input type=text size=5 name="entry">

    <input type=button value="Enqueue"

    onClick="enqueue()">

    <input type=button value="Dequeue"

    onClick="dequeue()">

    </form>

    <hr>

    <b>Stack:</b>

    <form name="stack">

    <table>

    <tr>

    <td>Entry: <input type=text size=5

    name="entry"><br>

    <input type=button value="Push"

    onClick="push()"><br>

    <input type=button value="Pop"

    onClick="pop()"> <br>

    <input type=button value="Peek"

    onClick="peek()"><br>

    </td>

    <td><textarea name=display

    rows=20></textarea></td>

    </tr>

    </table>

    </form>

    </center>

    <script language="JavaScript">

    var myqueue = new Array();

    var front;

    var back;

    front = 0;

    back = -1;

    var mystack = new Array();

    var top;

    top = -1;

    1 AnswerProgramming & Design10 years ago
  • help with javascript problem...search function?

    These are the instructions for this javascript problem

    first i have to randomly initialize a list of size 200 with integer values between 0 and 100. then i have to promp the user once for an element between 0 to 100 to search for....next i have to call a search function with the number to search for and the list...last display whether the number was found and if so a lcaiton where it can be found within the list

    this is what I have, but when I try to open it as a html file, its blank...please any help with what errors i have or wrong codes would be helpful. Thanks.....

    <html>

    <head>

    <script language = "javascript">

    var lists = new Array(200);

    var i;

    for (i=0; i<100; i++)

    {

    lists[i]=Math.floor(Math.random()*100;)

    }

    Array.prototype.indexAt = function(){

    for(var i = 0; i < this.length; i++){

    if(this[i]===arguments[0])

    return i;

    };

    return -1;

    }

    var foundItems = [];

    var index = array.indexOf(element)

    while (index != -1)

    {

    foundItems.push(index);

    index = array.indexOf(element, ++index);

    }

    </head>

    </html>

    </script>

    3 AnswersProgramming & Design10 years ago
  • Javascript scoping error?

    I have a scoping error in both programs...in program one i know the answer is suppose to be x=65, y=80, but its not coming up with x=65. In program 2, i know the answer is suppose to be 275. Any help???

    <html>

    <head>

    <title> </title>

    </head>

    <body>

    <script>

    // The "main" program

    var x;

    var y;

    x = average(10, 20) + average(30, 50) + average(0,

    20);

    y = average(10, 70) + average(30, 50);

    document.write("<b>Program 1:</b> <br>");

    document.write("The correct answer is: x =" + x + ",

    y = " + y + ".<br>");

    // This function takes in two numbers and returns

    the average.

    function average(u, v)

    {

    x = (u + v) / 2;

    return x;

    }

    </script>

    <!--

    *******************************************************

    ******** -->

    <!-- Program 2 -->

    <!--

    *******************************************************

    ******** -->

    <script>

    // The "main" program

    var total;

    var x;

    var i;

    total = 0;

    x = 10;

    for (i = 0; i < 5; i++) {

    total = total + adder(x);

    }

    document.write("<b>Program 2:</b> <br>");

    document.write("The correct answer is: " + total +

    ".");

    // This function takes in an integer and adds it

    // plus all previous integers together.

    // For example, if n=3, result = 0 + 1 + 2 + 3

    function adder(n)

    {

    var result = 0;

    for (i = 0; i < (n+1); i++)

    result = result + i;

    return result;

    }

    </script>

    </body>

    </html>

    2 AnswersProgramming & Design10 years ago
  • javascript calculator with three text boxes and 4 buttons?

    How to make this work???

    <html>

    <head>

    <title> COP 2500 Lab 6 Solution </title>

    <script language = "javascript">

    function add()

    {

    var left = parseFloat(document.getElementById('left').value);

    document.getElementById('answer').value = "";

    }

    </script>

    </head>

    <body>

    <input type = "text" id = "left" >

    <button onclick="add()">+</button>

    <button onclick="">-</button>

    <button onclick="">*</button>

    <button onclick="">/</button>

    <input type = "text" id = "right" >

    =

    <input type = "text" id = "answer" >

    </body>

    2 AnswersProgramming & Design10 years ago
  • if then else blocks and LOOPS?

    Convert the following two algorithms into JavaScript code within your HTML document. Your final web page should display the algorithm title, the input and the output. The specific format you use to display the results is up to you, but it should be clear what the input and output means (in other words, don't just list rows of numbers without words or labels describing them). The first algorithm calculates the sum total of a list of numbers. The second algorithm, compares pairs of numbers from two different lists.

    Summing a list of numbers.

    INPUT: var list1[10;

    OTHER VARIABLES: var sum; var i;

    INITIALIZATION: FOR i = 0 to 9 DO

    list[i] = random integer between 0 and 100;

    END DO

    sum = 0;

    COMPUTATION: FOR i = 0 to 9 DO

    sum = sum + list[i];

    ENDDO

    OUTPUT: Display sum using document.write() or something similar.

    Compare numbers from two separate lists

    INPUT: var list1[10], list2[10];

    OTHER VARIABLES: var i;

    INITIALIZATION: FOR i = 0 to 9 DO

    list1[i] = random number between 0 - 100;

    list2[i] = random number between 0 - 100;

    ENDDO

    COMPUTATION: FOR i = 0 to 9 DO

    IF ( list1[i] > list2[i]) THEN

    print(list1[i] + "is greater than" + list2[i]);

    ELSE

    print(list1[i] + "is less than" + list2[i]);

    ENDIF

    ENDDO

    1 AnswerProgramming & Design10 years ago