Write a program that asks a user to enters pairs of numbers until they enter "quit". As each pair of numbers is entered and validated, add the numbers using a function. The function will have two parameters for the pair of numbers and will return the sum. After the user enters "quit", output all the pairs of numbers and their sums.
1
Expert's answer
2016-05-13T10:08:03-0400
// creating variables and array var num1 = 0, num2 = 0, arrNum = [1];
// functiond that add 2 numbers function sum(num1, num2) { var sum = 0; sum = Number(num1) + Number(num2); return sum; }
//function that check var number for quit function checkExit(num) { if(num == 'quit') { return true; } else return false; }
function printArr(arrNum) { document.write("Entries Sum"); document.write("<br><br>"); for (var i = 1; i < arrNum.length; i+=3) { document.write(arrNum[i] + ' ' + arrNum[i+1] + ' ' + arrNum[i+2]); document.write("<br><br>"); } }
while(true) { //enteting num1 and num2 num1 = prompt('Enter 1 number of pair', 0); //checking for quit if(checkExit(num1) == true) break; //adding nums to array for output in the end arrNum.push(num1);
num2 = prompt('Enter 2 number of pair', 0); if(checkExit(num2) == true) break;
arrNum.push(num2); //calculating and adding sum to array arrNum.push(sum(num1, num2)); } //printing numbers and sums printArr(arrNum);
Finding a professional expert in "partial differential equations" in the advanced level is difficult.
You can find this expert in "Assignmentexpert.com" with confidence.
Exceptional experts! I appreciate your help. God bless you!
Comments
Dear customer, Please submit it with all requirements as an assignment to our control panel and we'll assist you.
Can this be done without the array? I can send the file if need be
Leave a comment