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

JavaScript Programming-Assignment #1 1. Write a program that prompts the user fo

ID: 3709457 • Letter: J

Question

JavaScript Programming-Assignment #1 1. Write a program that prompts the user for three numbers. Then using the alert function, display the average, product, and sum of the three numbers. 2. Write a program that ask for the user's first name and user's last name. Have the program then use the alert function to display data. Your First Name: Your Last Name: Your Complete Names is: 3. Write a program that asks the user if it is raining, snowing, windy, sunny or humid outside. Using conditional statements, determine what your alert function will tell the user. HINT: You must have five different outputs for each of the five possible cases. 4. Write a program that ask the user to input their age. Then using console.log () print out how long they have been alive in weeks, days, minutes and seconds. 5. Create a function that takes the average of the all numbers in an array. The function must be able t handle any size. Print out the contents of the size array

Explanation / Answer

1)answer:

<Script type="text/javascript">

firstnum=window.prompt("enter first number:");

secnum=window.prompt("enter second number:");

thirdnum=window.prompt("enter third number:");

var first=parseInt(firstnum);

var second=parseInt(secnum);

var third =parseInt(thirdnum);

var sum=first+second+third;

var avg=sum/3;

var prod=first*second*third;

window.alert("SUM :"+sum+" Average:"+avg+" Product:"+prod);

</script>

save the above code with .htm extension and double click on it to run in a browser (script tag is for running in the browser)

2) answer:

<script>

firstname=window.prompt("Your First name:");

lastname=window.prompt("Your Last name:");

window.alert("Your Complete Name is : "+first name+lastname);

</script>

save and run in browser as 1st one

3)answer:

<script>

var opt=window.prompt("how is the weather outside? 1.raining 2.snowing 3.windy 4.sunny 5.humid select appropriate option(number) from the above 5 weather states:");

var option=parseInt (opt);

if(option==1){

window.alert("bring umbrella with you! Because it is raining");

}

else if(option==2){

window.alert("wear a jacket because it is snowing");

}

else if(option==3){

window.alert("go outside and enjoy the wind");

}

else if(option==4){

window.alert("don't wear dark coloured clothes like black");

}

else if(option==5){

window.alert("humidity makes hot weather more unbearable");

}

else{

window.alert("weather is unknown");

}

</script>

save and run in browser to get output

<script>

var age=window.prompt("enter your age:");

var x=parseInt (age);

console.log("alive in weeks:"+(52.14*x));

console.log("alive in days:"+(365*x));

console.log("alive in minutes:"+(525600*x));

console.log("alive in seconds:"+(525600*60*x));

</script>

save it and run in browser and press F12 to view console in ththat select console to see the results of console.log() function.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote