Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

IN HTML Javascript In each instance where you ask the user how many items they want, trap them in a loop until they give you

IN HTML Javascript

In each instance where you ask the user how many items they want, trap them in a loop until they give you a whole, positive number (there is a slide in the PowerPoints for this).

PLEASE HELP. I am having issues being trapped in a loop after entering not a whole number ( example 4.5). I am able to continue when is NaN and when it is a negative. I am just trying to be able to access the next prompt statement after receiving a whole number and no longer be trapped.

This is the example code given in the power point

var bracelets = parseInt(prompt("How many bracelets do you want?"," "));

var check = bracelets % 1;

while(isNaN(bracelets) || (bracelets < 0) || (check != 0)) {

bracelets = prompt("Please enter a positive whole number. How many bracelets do you want?"," ");

}

This is my code within my first function.

function first{

var name = parseInt(prompt("Enter the amount of vinyls you would like: "));

var check = name % 1;

while(name<0 || isNaN(name) || (check !=0)) {

name=prompt("Please enter a valid amount for vinyls you would like to purchase: ");

}

var sign = parseInt(prompt("Enter 1 for regular, Enter 2 for signed copies"));

while (sign != 1 && sign != 2 ){

var sign = prompt("Please enter 1 for regular, Enter 2 for signed copies");

}

var price = parseInt(name)* 20;

var signed = parseInt(name) * 40;

if (sign ==1){

alert("Your price is $" + price); }

else if(sign==2){ alert("Your price is $" + signed) }

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Graph Databases New Opportunities For Connected Data

Authors: Ian Robinson, Jim Webber, Emil Eifrem

2nd Edition

1491930896, 978-1491930892

More Books

Students also viewed these Databases questions

Question

Determine miller indices of plane X z 2/3 90% a/3

Answered: 1 week ago