Resolução do Exercício de JavaScript (Aula 20/10/2011)
Autor: Grupo AIC - I | Publicado: 2011-10-20T11:23:00-02:00


Algoritmo em java para o usuário informar a quantidade &nbsp;de maçãs e laranjas que foram compradas. Quando a quantidade for maior que uma duzia, tanto da maçã, quanto o valor da laranja é R$ 2,50.&nbsp;Caso contrário o valor é R$ 2,95. Depois de informado o valor imprima o valor gasto comprando as maçãs e as laranjas, e imprimir seu total. Caso o valor total for maior ou igual a R$ 50,00 deve se dar um desconto de 10% sobre o valor total. Depois imprima o valor a ser pago, ou seja, o valor total menos o desconto.




&lt;html&gt;&lt;head&gt;&nbsp;&lt;title&gt;Fomos a Feira!&lt;/title&gt;&lt;/head&gt;&lt;body&gt;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&lt;script language="Javascript"&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; quantmacas = prompt ("Quantas maçãs você irá comprar?");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; quantlaranjas = prompt ("Quantas laranjas você irá comprar?");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; macas = parseFloat (quantmacas);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; laranjas = parseFloat (quantlaranjas);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(quantmacas&gt;=12){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; valorduziam = (quantmacas/12) * 2.50;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else{&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; valorduziam = (2.95/12)*quantmacas;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(quantlaranjas&gt;=12){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; valorduzial = (quantlaranjas/12) * 2.50;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else{&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; valorduzial = (2.95/12)*quantlaranjas;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; document.write("&lt;p&gt;A quantidade de maçãs é:" +quantmacas+ "&lt;/p&gt;");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; document.write("&lt;p&gt;O valor total das maçãs:" +valorduziam+ "&lt;/p&gt;");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; document.write("&lt;p&gt;A quantidade de laranjas é:" +quantlaranjas+ "&lt;/p&gt;"); &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; document.write("&lt;p&gt;O valor total das laranjas é:" +valorduzial+ "&lt;/p&gt;");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; total = valorduziam + valorduzial;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;document.write("&lt;p&gt;O valor total é:" +total+ "&lt;/p&gt;");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(total&gt;=50){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; desconto = (total * 10) / 100;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; document.write("&lt;p&gt;O desconto é de:" +desconto+ "&lt;/p&gt;");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; totalcomdesc = total - desconto;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; document.write("&lt;p&gt;O Valor com desconto é:" +totalcomdesc+ "&lt;/p&gt;");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else{&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; document.write("&lt;p&gt;O valor total é:" +total+ "&lt;/p&gt;");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &lt;/script&gt;

&lt;/body&gt;

&lt;/html&gt;