Question

In: Computer Science

Write a program that uses an array for time and temperature. The program should contain an...

Write a program that uses an array for time and temperature. The program should contain an array with 24 elements, each of which is holding a temperature for a single hour.

Your program should have a function that lists all of the temperatures that are held in the array. Temperatures should be listed to console with one entry per line.

Your program should have a function that lists a single temperature entry. You should ask the user for a number and list that entry from newest to oldest. For example if the user enters 5, then you should show the entry from 5 hours ago.

Your program should have a function that adds an entry to the array and shifts the oldest entry out of the array. (You must keep 24 entries.)

Your program should ask the user if they want to list all of the entries, list a single entry, or enter a new entry. Your program should continue to loop until the user clicks the cancel button OR clicks the enter button without entering a choice.

use let
And console.log for the coding

Javascript language console.log and use let

Solutions

Expert Solution

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <script>
//for testing 
        //let temp = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24];
let temp=[]
        function AddEntry() {
            let x = prompt("Enter Temperature:");
            temp.unshift(x);
            if (temp.length > 24)
                temp.pop();
        }

        function SingleEntry() {

            num = prompt("Enter Number");

            let temp_at = temp[parseInt(num) - 1];
            console.log("Temperature :", temp_at);


        }

        function ListAllEntry() {
            for (let i = 0; i < temp.length; i++)
                console.log(temp[i]);
        }
        let loop = true;

        while (loop) {

            let choice = prompt("Enter Choice :\n1.Show all Entry\n2.Add temp\n3.Show Single Entry\n")
            if (choice === null) {
                loop = false;
                break;
            }
            // console.log(choice," ",typeof(choice));
            switch (choice) {
                case "1":
                    ListAllEntry();
                    break;
                case "2":
                    AddEntry();
                    break;
                case "3":
                    SingleEntry();
                    break;
            }
        }
    </script>

</body>

</html>

Related Solutions

Write a Java program that reads a list of integers into an array. The program should...
Write a Java program that reads a list of integers into an array. The program should read this array from the file “input.txt”. You may assume that there are fewer than 50 entries in the array. Your program determines how many entries there are. The output is a two-column list. The first column is the list of the distinct array elements; the second column is the number of occurrences of each element. The list should be sorted on entries in...
Write a recursive method to determine if a String is a palindrome. The program should contain...
Write a recursive method to determine if a String is a palindrome. The program should contain a String array that you can load several test cases to test your palindrome testing method. The program should load your String Array with the test data containing the possible palindromes from a text file. The program should test you application with a text file contained in your project folder After testing your program with your test cases in the text file, you program...
Write a recursive method to determine if a String is a palindrome. The program should contain...
Write a recursive method to determine if a String is a palindrome. The program should contain a String array that you can load several test cases to test your palindrome testing method. The program should load your String Array with the test data containing the possible palindromes from a text file. The program should test you application with a text file contained in your project folder After testing your program with your test cases in the text file, you program...
In C++, write a program that uses array to calculate the factorial of a reasonable large...
In C++, write a program that uses array to calculate the factorial of a reasonable large number (say, up to 2,000).
In C++. Write a program that uses array to calculate the factorial of a reasonable large...
In C++. Write a program that uses array to calculate the factorial of a reasonable large number (say, up to 2,000).  
Write a program that uses an array of doubles initialized to whatever values you wish. Write...
Write a program that uses an array of doubles initialized to whatever values you wish. Write methods to calculate and return the minimum and a method to calculate and return the maximum value in the array. You must write YOUR ORIGINAL methods for minimum and maximum. You MAY NOT use Math class methods or other library methods. Write an additional method that accepts the array as a parameter and then creates and returns a new array with all the same...
IN JAVA Write a program with a method that returns an array. The method should accept...
IN JAVA Write a program with a method that returns an array. The method should accept as input a comma-delimited string with three values from a user. The array should store each value in a different element. Use Try..Catch error handling and print any failure messages, or print success from within method if the execution is successful (see Chapter 13 in the text). Call the method from the main method of the program to demonstrate its functionality by looping through...
Write a program that uses a DYNAMIC two-dimensional array to store the highest and lowest temperatures for each month of the year (temperature is a decimal value)
In c++ Write a program that uses a DYNAMIC two-dimensional array to store the highest and lowest temperatures for each month of the year (temperature is a decimal value). The program should output the highest and lowest temperatures for the year. Your program must consist of the following functions: a. Function getData: This function reads and stores data in the two-dimensional array. b. Function indexHighTemp: This function returns the index of the highest high temperature in the array. c. Function...
Write a program that uses a DYNAMIC two-dimensional array to store the highest and lowest temperatures for each month of the year (temperature is a decimal value)
In c++ Write a program that uses a DYNAMIC two-dimensional array to store the highest and lowest temperatures for each month of the year (temperature is a decimal value). The program should output the highest and lowest temperatures for the year. Your program must consist of the following functions: a. Function getData: This function reads and stores data in the two-dimensional array. b. Function indexHighTemp: This function returns the index of the highest high temperature in the array. c. Function...
Write a program that uses a DYNAMIC two-dimensional array to store the highest and lowest temperatures for each month of the year (temperature is a decimal value)
In C++ c. The program should output the highest and lowest temperatures for the year. Your program must consist of the following functions: a. Function getData: This function reads and stores data in the two-dimensional array. b. Function indexHighTemp: This function returns the index of the highest high temperature in the array. c. Function indexLowTemp: This function returns the index of the lowest low temperature in the array. These functions must all have the appropriate parameters.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT