Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. write a program that will help calculate tip. you will need to get two values

ID: 3548753 • Letter: 1

Question

1. write a program that will help calculate tip. you will need to get two values from the user. ask user for both, the pre-tax cost and what percent of tip they want to give.


2. write a javascript program that generates random numbers and adds to a sum, stopping when the sum becomes greater than 1000. count the numbers as you generate them, and output the count at the end.


3. design an algorithm that will prompt a teacher for student's name and hs score and display " Student <name of student> git the following grade <grade>


Find the grade based on this info


50 below F, between 51 and 60 D, 61 and 70 C.....and so on


these are the ones i need help with but have two more if you are willing to help after these and i will add more points Thanks

Explanation / Answer

Hi,


Based on the comment am giving answer only for 2 point i.e for random number.


A javascript loads on body load function, then it calculates the random number. it will show the count of random no as alert and in the text box in the html page. PFB. calculateRandom() is javascript function. save the below code as ahtml file and open it in browser, you can see the result. Hope it helps.


<html>
<head>
<script>
function calculateRandom()
{
var sum =0;
var count = 0;
while(sum<=1000)
{
var randomnumber= Math.floor(Math.random()*11);
sum= sum +randomnumber;
count = count +1;
}
alert("no of time random no generated" + count);
document.getElementById("txtCount").value=count;
}
</script>
</head>
<body>Random number count:
<input type="text" id="txtCount"/>
<br/>

</body>
</html>


the line in the above script var randomnumber= Math.floor(Math.random()*11); will generate a no from 0 to 10. You can also give var randomnumber= Math.floor(Math.random()*1001); to take any no from 0 to 1000.


PFB the modified program.


<html>
<head>
<script>
function calculateRandom()
{
var sum =0;
var count = 0;
while(sum<=1000)
{
var randomnumber= Math.floor(Math.random()*1001);
sum= sum +randomnumber;
count = count +1;
}
alert("no of time random no generated" + count);
document.getElementById("txtCount").value=count;
}
</script>
</head>
<body>Random number count:
<input type="text" id="txtCount"/>
<br/>

</body>
</html>


Thanks,

Sri