SÁU JavaScript Programs VIẾT HÓA ĐƠN BÁN SỈ VÀ BÁN LẺ.
1- PROGRAM CÓ CONFIRM ( ) ĐỂ XÁC NHẬN TRƯỚC.
- CẦN 24 LINES OF CODES
- HOÁ ĐƠN KHÔNG XUẤT HIÊN NHỮNG CON SỐ KHÔNG CẦN, CÓ TOTAL PAY VÀ SỐ LƯỢNG MUA ĐI KÈM THEO TIỀN MUA SỐ LƯƠNG ĐÓ.
var shop = {
greeting :" <span style='color:red'>WELCOME TO : ENRIQUE SHOP</span>" ,
product :"CHÚNG TÔI BÁN RICE VÀ SUGAR VỚI GIÁ SỈ VÀ LẺ \n RICE BAG : 5 lbs \n SUGAR BAG : 2 lbs ",
appreciation :"<span style='color:red'>THANK YOU , SEE YOU AGAIN ! </span>",}
document.write(shop.greeting +"<br>");
alert(shop.product);
alert("IF YOU DO NOT WANT ANY,PLS CLICK OK \n THEN PUT ZERO IN LATER \n DO NOT CLICK CANCEL");// lý do phải có đ̉ủ 2 con số kể cả zero mới cho tổng cộng TOTAL PAY.
var yes1 = confirm("DO YOU WANT TO BUY OVER 100 RICE BAGS?");
if(yes1 == true){var x1=prompt("HOW MANY WHOLESALE RICE BAGS YOU WANT?")};
var pay1 = parseInt(x1*4.00);
document.write( " * PAY WHOLESALE RICE : "+x1+" "+" bags" +" "+ pay1 + " " + "USD" +"<br>");
if(yes1==false){x1=0;pay1=0} // phải có mới tổng cộng được
var yes2 = confirm("DO YOU WANT TO BUY RETAIL RICE BAGS?");
if(yes2==true){var x2=prompt("HOW MANY RETAIL RICE BAGS YOU WANT?")};
var pay2 = parseFloat(x2*5.25);
document.write( " * PAY RETAIL RICE : "+x2+" "+"bags" +" "+ pay2 + " " + "USD" +"<br>");
if(yes2=false){x2=0;pay2=0} // phải có mới tổng cộng được
var yes3 = confirm("DO YOU WANT TO BUY OVER 100 SUGAR BAGS?");
if(yes3 == true){var y1= prompt("HOW MANY WHOLESALE SUGAR BAGS YOU WANT?")};
var pay3 = parseInt(y1*3.00);
document.write( " * PAY WHOLESALE SUGAR : " + y1 +" "+" bags" +" "+ pay3 + " " + "USD" +"<br>");
if(yes3==false){y1=0;pay3=0} // phải có mới tổng cộng được
var yes4 = confirm("DO YOU WANT TO BUY RETAIL SUGAR BAGS?");
if(yes4=true){var y2=prompt("HOW MANY RETAIL SUGAR BAGS YOU WANT?")};
var pay4 = parseFloat(y2*3.25);
document.write( " * PAY RETAIL SUGAR : " + y2 +" "+" bags" +" "+ pay4 + " " + "USD" +"<br>");
if(yes4==false){y2=0;pay4=0} // phải có mới tổng cộng được
var T = pay1+pay2+pay3+pay4;
var today = new Date();
var day = today.getDate();
var month = today.getMonth()+1; //January is 0!
var year = today.getFullYear();
document.write("* <span style='color:blue'>TOTAL PAY : </span>" + T +" "+ "USD"+ "<br>"+
shop.appreciation + "<br>"+
"* MANAGER : BAXAO XAOKE "+"<br>"+
"* YEAR :" + year + " , " + "MONTH : " + month + "<br>"+
"* DAY : " + today);
OUTPUT OF PROGRAM 1.
WELCOME TO : ENRIQUE SHOP
* PAY WHOLESALE RICE : 150 bags 600 USD
* PAY RETAIL RICE : 0 bags 0 USD
* PAY WHOLESALE SUGAR : 0 bags 0 USD
* PAY RETAIL SUGAR : 80 bags 260 USD
* TOTAL PAY : 860 USD
THANK YOU , SEE YOU AGAIN !
* MANAGER : BAXAO XAOKE
* YEAR :2016 , MONTH : 2
* DAY : Sat Feb 06 2016 16:47:20 GMT-0800 (Pacific Standard Time)
--------------------
PROGRAM 2
* MUỐN MUA SỐ LƯƠNG BAO NHIÊU TUỲ Ý KHÔNG BẮT BUỘC PHẢI CONFIRM ( )
* CÓ 14 LINES OF CODES.
* CHỈ NHÌN VÀO HÀNG CHỮ SẼ THẤY NGAY TỔNG SỐ TIỀN ‘TOTAL PAY’ PHẢI TRẢ.
var shop = {
greeting :" <span style='color:red'>WELCOME TO : ENRIQUE SHOP</span>" ,
product :"CHÚNG TÔI BÁN RICE VÀ SUGAR VỚI GIÁ SỈ VÀ LẺ \n RICE BAG : 5 lbs \n SUGAR BAG : 2 lbs ",
appreciation :"<span style='color:red'>THANK YOU , SEE YOU AGAIN ! </span>", }
document.write(shop.greeting +"<br>");
alert(shop.product);
alert("CHÚNG TÔI BÁN SỈ VÀ BÁN LẺ MUA DƯỚI 100 THÌ TRẢ GIÁ LẺ")
var x= parseInt(prompt('HOW MANY RICE BAGS DO YOU WANT ?')); //hỏi như vậy nhưng viết vaò con số tuỳ ý.
var pay2=parseFloat(x*5.25)
if(x<100){document.write("YOU PAY retail RICE : " +pay2+ " "+ "USD"+"<br>")}
var pay1=parseInt(x*4,00)
if(x>=100){document.write("YOU PAY WHOLESALE RICE : " +pay1+ " "+ "USD"+"<br>")}
var y= parseInt(prompt('HOW MANY SUGAR BAGS DO YOU WANT?' ));
var pay4=parseFloat(y*3.25)
if(y<100){document.write("YOU PAY retail SUGAR : " +pay4 + " "+ "USD"+"<br>")}
var pay3=parseInt(y*3.00)
if(y>=100){document.write("YOU PAY WHOLESALE SUGAR : " +pay3+ " "+ "USD"+"<br>")}
var T= x+y;//không làm parseInt nữa vì đã làm ở trên parseInt
// rice pay is considered the start point.
var T1 = pay2+pay4;// wholesale rice plus wholesale sugar
var T2 = pay1+pay3; //retail rice plus retail sugar
var T3 = pay1+pay4; //retail rice plus wholesale sugar
var T4 = pay2+pay3; // wholesale rice plus retail sugar
var today = new Date();
var day = today.getDate();
var month = today.getMonth()+1; //January is 0!
var year = today.getFullYear();
document.write("1-RICE BAGS : " + x + "<br>"+
"2-SUGAR BAGS : " + y + "<br>"+
"* Retail RICE PLUS Retail SUGAR : " + T1 +" "+ "USD"+ "<br>"+
"* WHOLESALE RICE PLUS WHOLESALE SUGAR : " + T2 +" "+ "USD"+ "<br>"+
"* WHOLESALE RICE PLUS Retail SUGAR : " + T3 +" "+ "USD"+ "<br>"+
"* Retail RICE PLUS WHOLESALE SUGAR : " + T4 +" "+ "USD"+ "<br>"+
shop.appreciation + "<br>"+
"3-MANAGER : BAXAO XAOKE "+"<br>"+
"* YEAR :" + year + " , " + "MONTH : " + month + "<br>"+
"* DAY : " + today);
OUTPUT OF PROGRAM 2.
WELCOME TO : ENRIQUE
SHOP
YOU PAY WHOLESALE RICE : 600 USD
YOU PAY retail SUGAR : 260 USD
1- RICE BAGS : 150
2- SUGAR BAGS : 80
* Retail RICE PLUS Retail SUGAR : 1047.5 USD
* WHOLESALE RICE PLUS WHOLESALE SUGAR : 840 USD
* WHOLESALE RICE PLUS Retail SUGAR : 860 USD
* Retail RICE PLUS WHOLESALE SUGAR : 1027.5 USD
THANK YOU , SEE YOU AGAIN !
3- MANAGER : BAXAO XAOKE
* YEAR :2016 , MONTH : 1
* DAY : Tue Jan 26 2016 05:56:19 GMT-0800 (Pacific Standard Time)
YOU PAY WHOLESALE RICE : 600 USD
YOU PAY retail SUGAR : 260 USD
1- RICE BAGS : 150
2- SUGAR BAGS : 80
* Retail RICE PLUS Retail SUGAR : 1047.5 USD
* WHOLESALE RICE PLUS WHOLESALE SUGAR : 840 USD
* WHOLESALE RICE PLUS Retail SUGAR : 860 USD
* Retail RICE PLUS WHOLESALE SUGAR : 1027.5 USD
THANK YOU , SEE YOU AGAIN !
3- MANAGER : BAXAO XAOKE
* YEAR :2016 , MONTH : 1
* DAY : Tue Jan 26 2016 05:56:19 GMT-0800 (Pacific Standard Time)
GHI CHÚ.
Quan sát 2 con số 600 USD và 260 USD thì thấy ngay con số tổng cộng là 860 USD nhờ có câu WHOLESALE RICE PLUS Retail SUGAR
SO SÁNH 2 PROGRAMS,CHÚNG TA THẤY RÕ PROGRAM NAÒ NGẮN GỌN VÀ TIỆN LỢI?
NẾU
CỮA HÀNG BÁN THÊM CAFÉ BỘT VÀ SỬA HỘP THÌ VIẾT THÊM CODES NHƯ SAU VÀO PROGRAM SỐ 1..
var shop = {
greeting :" <span
style='color:red'>WELCOME TO : ENRIQUE SHOP</span>",
product :"CHÚNG TÔI BÁN RICE
VÀ SUGAR VỚI GIÁ SỈ VÀ LẺ \n RICE BAG : 5 lbs \n SUGAR BAG : 2 lbs
",
appreciation :"<span style='color:red'>THANK YOU , SEE YOU AGAIN !
</span>",
rice :"WOULD YOU WANT TO BUY
RICE?",
sugar:"WOULD YOU WANT TO BUY
SUGAR?",}
document.write(shop.greeting +"<br>");
alert(shop.product);
alert("IF
YOU DO NOT WANT ANY,PLS CLICK OK \n THEN PUT ZERO IN LATER \n DO NOT CLICK
CANCEL");
var yes1 = confirm("DO
YOU WANT TO BUY OVER 100 RICE BAGS?");
if(yes1 == true){var x1=prompt("HOW MANY WHOLESALE RICE BAGS YOU
WANT?")};
var pay1 = parseInt(x1*4.00);
document.write(
" * PAY WHOLESALE RICE : "+x1+" "+" bags" +"
"+ pay1 + " " + "USD" +"<br>");
if(yes1==false){x1=0;pay1=0}
// phải có mới tổng cộng được
var yes2 = confirm("DO
YOU WANT TO BUY RETAIL RICE BAGS?");
if(yes2==true){var x2=prompt("HOW MANY RETAIL RICE BAGS YOU
WANT?")};
var pay2 = parseFloat(x2*5.25);
document.write(
" * PAY RETAIL RICE : "+x2+" "+"bags" +"
"+ pay2 + " " + "USD" +"<br>");
if(yes2=false){x2=0;pay2=0} // phải có mới tổng cộng
được
var yes3 = confirm("DO
YOU WANT TO BUY OVER 100 SUGAR BAGS?");
if(yes3 == true){var y1= prompt("HOW MANY WHOLESALE SUGAR BAGS YOU
WANT?")};
var pay3 = parseInt(y1*3.00);
document.write(
" * PAY WHOLESALE SUGAR : " + y1 +" "+" bags"
+" "+ pay3 + " " + "USD"
+"<br>");
if(yes3==false){y1=0;pay3=0}
// phải có mới tổng cộng được
var yes4 = confirm("DO
YOU WANT TO BUY RETAIL SUGAR BAGS?");
if(yes4=true){var y2=prompt("HOW MANY RETAIL SUGAR BAGS YOU
WANT?")};
var pay4 = parseFloat(y2*3.25);
document.write(
" * PAY RETAIL SUGAR : " + y2 +" "+" bags"
+" "+ pay4 + " " + "USD"
+"<br>");
if(yes4==false){y2=0;pay4=0} // phải có mới tổng cộng
được
var caf
= parseInt(prompt("HOW MANY COFFEE POTS
YOU WANT ?"));
var pay5 =
parseFloat(caf*7.50);
document.write("*YOU
PAY FOR COFFEE : " + caf + " "+"pots"+ " "+ pay5 +" " + "USD" +
"<br>");
var mk
= parseInt(prompt("HOW MANY MILK CANS YOU
WANT ?"));
var pay6 =
parseFloat(mk*1.75);
document.write("*YOU
PAY FOR MILK CANS : " + mk +" "+"cans"+ " "+
pay6 +" " + "USD" +
"<br>");
var T = pay1+pay2+pay3+pay4+pay5+pay6;
var today = new Date();
var day = today.getDate();
var month = today.getMonth()+1;
//January is 0!
var year = today.getFullYear();
document.write("*
<span style='color:blue'>TOTAL PAY :
</span>" + T +" "+ "USD"+
"<br>"+
shop.appreciation + "<br>"+
"* MANAGER : BAXAO
XAOKE "+"<br>"+
"* YEAR :" +
year + " , " + "MONTH : " + month +
"<br>"+
"* DAY : " +
today);
OUTPUT RECEIPT.
WELCOME TO : ENRIQUE SHOP
* PAY WHOLESALE RICE : 0 bags 0 USD
* PAY RETAIL RICE : 0 bags 0 USD
* PAY WHOLESALE SUGAR : 0 bags 0 USD
* PAY RETAIL SUGAR : 0 bags 0 USD
*YOU PAY FOR COFFEE : 1 pots 7.5 USD
*YOU PAY FOR MILK CANS : 1 cans 1.75 USD
* TOTAL PAY : 9.25 USD
THANK YOU , SEE YOU AGAIN !
* MANAGER : BAXAO XAOKE
* YEAR :2016 , MONTH : 1
* DAY : Sat Jan 30 2016 06:31:11 GMT-0800 (Pacific Standard Time)
* PAY WHOLESALE RICE : 0 bags 0 USD
* PAY RETAIL RICE : 0 bags 0 USD
* PAY WHOLESALE SUGAR : 0 bags 0 USD
* PAY RETAIL SUGAR : 0 bags 0 USD
*YOU PAY FOR COFFEE : 1 pots 7.5 USD
*YOU PAY FOR MILK CANS : 1 cans 1.75 USD
* TOTAL PAY : 9.25 USD
THANK YOU , SEE YOU AGAIN !
* MANAGER : BAXAO XAOKE
* YEAR :2016 , MONTH : 1
* DAY : Sat Jan 30 2016 06:31:11 GMT-0800 (Pacific Standard Time)
********************
PROGRAM 3.
PROGRAM NẦY CÓ
TỔNG CỘNG 13 LINES OF CODES.
NGẮN GỌN NHỨT VÀ
CÓ THỂ VIẾT THÊM CODES CỦA COFFEE POTS VÀ MILK CANS.
var shop = {
greeting :" <span
style='color:red'>WELCOME TO : ENRIQUE SHOP</span>" ,
product :"CHÚNG TÔI BÁN RICE
VÀ SUGAR VỚI GIÁ SỈ VÀ LẺ \n RICE BAG : 5 lbs \n SUGAR BAG : 2 lbs
",
appreciation :"<span style='color:red'>THANK YOU , SEE YOU AGAIN !
</span>", }
document.write(shop.greeting +"<br>");
alert(shop.product);
alert("IF
YOU DO NOT WANT ANY,PLS PUT ZERO \n THEN CLICK OK \n DO NOT CLICK
CANCEL");
var x1=prompt("HOW MANY RICE
BAGS YOU WANT?")
var pay1 = parseInt(x1*4.00);
if(x1>100){document.write( " * PAY
WHOLESALE RICE : "+x1+" "+" bags" +" "+ pay1
+ " " + "USD" +"<br>")};
var pay2 = parseFloat(x1*5.25);
if(x1<=100){pay1=0;document.write( " *PAY RETAIL RICE : "+x1+"
"+"bags" +" "+ pay2 + " " + "USD"
+"<br>")}
var y1= prompt("HOW MANY SUGAR
BAGS YOU WANT?");
var pay3 = parseInt(y1*3.00);
if(y1>100){document.write( " * PAY
WHOLESALE SUGAR : " + y1 +" "+" bags" +" "+
pay3 + " " + "USD" +"<br>")};
var pay4 = parseFloat(y1*3.25);
if(y1<=100){pay3=0;document.write( " * PAY RETAIL SUGAR : " + y1
+" "+" bags" +" "+ pay4 + " " +
"USD" +"<br>");}
var caf = parseInt(prompt("HOW MANY
COFFEE POTS YOU WANT ?"));
var pay5 = parseFloat(caf*7.50);
document.write("*YOU PAY FOR
COFFEE : " + caf + " "+"pots"+ " "+ pay5
+" " + "USD" + "<br>");
var mk = parseInt(prompt("HOW MANY MILK
CANS YOU WANT ?"));
var pay6 = parseFloat(mk*1.75);
document.write("*YOU PAY FOR
MILK CANS : " + mk +" "+"cans"+ " "+ pay6
+" " + "USD" + "<br>");
var T =
pay1+pay2+pay3+pay4+pay5+pay6;
var today = new Date();
var day = today.getDate();
var month = today.getMonth()+1;
//January is 0!
var year = today.getFullYear();
document.write("*
<span style='color:blue'>TOTAL PAY : </span>" + T +"
"+ "USD"+ "<br>"+
shop.appreciation +
"<br>"+
"* MANAGER : BAXAO
XAOKE "+"<br>"+
"* YEAR :" +
year + " , " + "MONTH : " + month +
"<br>"+
"* DAY : " +
today);
OUTPUT OF PRORAM 3.
WELCOME TO : ENRIQUE SHOP
*PAY RETAIL RICE : 1 bags 5.25 USD
* PAY RETAIL SUGAR : 0 bags 0 USD
*YOU PAY FOR COFFEE : 1 pots 7.5 USD
*YOU PAY FOR MILK CANS : 10 cans 17.5 USD
* TOTAL PAY : 30.25 USD
THANK YOU , SEE YOU AGAIN !
* MANAGER : BAXAO XAOKE
* YEAR :2016 , MONTH : 2
* DAY : Sun Feb 07 2016 09:14:58 GMT-0800 (Pacific Standard Time
*PAY RETAIL RICE : 1 bags 5.25 USD
* PAY RETAIL SUGAR : 0 bags 0 USD
*YOU PAY FOR COFFEE : 1 pots 7.5 USD
*YOU PAY FOR MILK CANS : 10 cans 17.5 USD
* TOTAL PAY : 30.25 USD
THANK YOU , SEE YOU AGAIN !
* MANAGER : BAXAO XAOKE
* YEAR :2016 , MONTH : 2
* DAY : Sun Feb 07 2016 09:14:58 GMT-0800 (Pacific Standard Time
********************
PROGRAM 4.
CÓ 16 LINES OF CODES. CHƯA
CÓ CODES LINES CỦA COFFEE POTS VÀ MILK CANS
var shop = {
greeting :" <span style='color:red'>WELCOME TO : ENRIQUE
SHOP</span>" ,
product :"CHÚNG TÔI BÁN RICE
VÀ SUGAR VỚI GIÁ SỈ VÀ LẺ \n RICE BAG : 5 lbs \n SUGAR BAG : 2 lbs
",
appreciation :"<span style='color:red'>THANK YOU , SEE YOU AGAIN !
</span>",}
document.write(shop.greeting
+"<br>");
alert(shop.product);
alert("IF
YOU DO NOT WANT ANY,PLS CLICK OK \n THEN PUT ZERO IN LATER \n DO NOT CLICK
CANCEL");
var yes1 = confirm("DO
YOU WANT TO BUY RICE BAGS?");
if(yes1 == true){var x=prompt("HOW MANY RICE BAGS YOU WANT?")};
var pay1 = parseInt(x*4.00);
if(x>=100){document.write( " * PAY WHOLESALE RICE : "+x+"
"+" bags" +" "+ pay1 + " " + "USD"
+"<br>")};
var pay2 = parseFloat(x*5.25);
if(x<100){pay1=0;document.write( " * PAY RETAIL RICE :
"+x+" "+"bags" +" "+ pay2 + " " +
"USD" +"<br>");}
var yes2 = confirm("DO
YOU WANT TO BUY SUGAR BAGS?");
if(yes2 == true){var y= prompt("HOW MANY SUGAR BAGS YOU WANT?")};
var pay3 = parseInt(y*3.00);
if( y>=100){document.write( " * PAY WHOLESALE SUGAR :
" + y +" "+" bags" +" "+ pay3 + "
" + "USD" +"<br>")};
var pay4 = parseFloat(y*3.25);
if(y<100){pay3=0;document.write( " * PAY RETAIL SUGAR : " +
y +" "+" bags" +" "+ pay4 + " " +
"USD" +"<br>")};
var T1 =
pay2+pay4;// wholesale rice plus wholesale sugar
var T2 =
pay1+pay3; //retail rice plus retail sugar
var T3 =
pay1+pay4; //retail rice plus wholesale
sugar
var T4 =
pay2+pay3; // wholesale rice plus
retail sugar
var today = new
Date();
var day =
today.getDate();
var month =
today.getMonth()+1; //January is 0!
var year =
today.getFullYear();
document.write("1-
RICE BAGS : " + x +
"<br>"+
"2- SUGAR BAGS : " + y +
"<br>"+
"* Retail RICE PLUS Retail
SUGAR : " + T1 +" "+ "USD"+ "<br>"+
"* WHOLESALE RICE PLUS
WHOLESALE SUGAR : " + T2 +" "+ "USD"+ "<br>"+
"* WHOLESALE RICE PLUS Retail
SUGAR : " + T3 +" "+ "USD"+ "<br>"+
"* Retail RICE PLUS WHOLESALE
SUGAR : " + T4 +" "+ "USD"+
"<br>"+
shop.appreciation +
"<br>"+
"3- MANAGER : BAXAO XAOKE
"+"<br>"+
"* YEAR :" + year + " , "
+ "MONTH : " + month + "<br>"+
"* DAY : " + today
);
OUTPUT OF PROGRAM 4.
WELCOME TO : ENRIQUE
SHOP
* PAY RETAIL RICE : 10 bags 52.5 USD
* PAY RETAIL SUGAR : 0 bags 0 USD
1- RICE BAGS : 10
2- SUGAR BAGS : 0
* Retail RICE PLUS Retail SUGAR : 52.5 USD
* WHOLESALE RICE PLUS WHOLESALE SUGAR : 0 USD
* WHOLESALE RICE PLUS Retail SUGAR : 0 USD
* Retail RICE PLUS WHOLESALE SUGAR : 52.5 USD
THANK YOU , SEE YOU AGAIN !
3- MANAGER : BAXAO XAOKE
* YEAR :2016 , MONTH : 2
* DAY : Sun Feb 07 2016 09:42:50 GMT-0800 (Pacific Standard Time)
* PAY RETAIL RICE : 10 bags 52.5 USD
* PAY RETAIL SUGAR : 0 bags 0 USD
1- RICE BAGS : 10
2- SUGAR BAGS : 0
* Retail RICE PLUS Retail SUGAR : 52.5 USD
* WHOLESALE RICE PLUS WHOLESALE SUGAR : 0 USD
* WHOLESALE RICE PLUS Retail SUGAR : 0 USD
* Retail RICE PLUS WHOLESALE SUGAR : 52.5 USD
THANK YOU , SEE YOU AGAIN !
3- MANAGER : BAXAO XAOKE
* YEAR :2016 , MONTH : 2
* DAY : Sun Feb 07 2016 09:42:50 GMT-0800 (Pacific Standard Time)
Program 5
Có 16 code lines + 6 code lines của café và milk
var shop = {
greeting :" <span
style='color:red'>WELCOME TO : ENRIQUE SHOP</span>" ,
product :"CHÚNG TÔI BÁN RICE
VÀ SUGAR VỚI GIÁ SỈ VÀ LẺ \n RICE BAG : 5 lbs \n SUGAR BAG : 2 lbs
",
appreciation :"<span
style='color:red'>THANK YOU , SEE YOU AGAIN ! </span>", }
document.write(shop.greeting +"<br>");
alert(shop.product);
alert("IF
YOU DO NOT WANT ANY,PLS PUT ZERO \n THEN CLICK OK \n DO NOT CLICK
CANCEL");
var x1 = parseInt(prompt("OVER 100 BAGS.\n HOW MANY WHOLESALE RICE BAGS YOU
WANT?"))
var pay1 = parseInt(x1*4.00);
document.write("* PAY WHOLESALE RICE : "+ x1 +" "+ "bags"+"
"+ pay1 +" "+ "USD" + "<br>");
var x2 = parseInt(prompt("LESS THAN 100 BAGS.\n HOW MANY RETAIL RICE BAGS
YOU WANT?"))
var pay2 = parseFloat(x2*5.25);
document.write("*PAY RETAIL RICE : "+ x2 +" "+" bags"+" "+
pay2 +" "+ "USD" + "<br>");
var y1 = parseInt(prompt("OVER 100 BAGS.\n HOW MANY SUGAR BAGS YOU
WANT?"));
var pay3 = parseInt(y1*3.00)
document.write("* PAY WHOLESALE SUGAR : "+ y1 +" "+ "bags"+ "
"+ pay3 +" "+ "USD" + "<br>")
var y2 =parseInt(prompt("LESS THAN 100 BAGS.\n HOW MANY SUGAR BAGS YOU
WANT?"));
var pay4 = parseFloat(y2*3.25);
document.write(" * PAY RETAIL SUGAR : "+ y2 +" "+"bags"+" "+ pay4 +"
"+ "USD" + "<br>");
var caf = parseInt(prompt("HOW MANY COFFEE POTS YOU WANT ?"));
var pay5 = parseFloat(caf*7.50);
document.write("*YOU PAY FOR COFFEE : " + caf + " "+"pots"+ " "+ pay5
+" " + "USD" + "<br>");
var mk = parseInt(prompt("HOW MANY MILK CANS YOU WANT ?"));
var pay6 = parseFloat(mk*1.75);
document.write("*YOU PAY FOR MILK CANS : " + mk +" "+"cans"+ " "+ pay6
+" " + "USD" + "<br>");
var T = pay1+pay2+pay3+pay4+pay5+pay6;
var today = new Date();
var day = today.getDate();
var month = today.getMonth()+1;//January is 0!
var year = today.getFullYear();
document.write("*<span style='color:blue'>TOTAL PAY : </span>" + T +"
"+ "USD"+ "<br>"+
shop.appreciation + "<br>"+
"* MANAGER : BAXAO XAOKE "+"<br>"+
"* YEAR :" + year + " , " + "MONTH : " + month + "<br>"+
"* DAY : " + today);
OUTPUT OF PROGRAM 5.
WELCOME TO : ENRIQUE SHOP
* PAY WHOLESALE RICE : 0 bags 0 USD
* PAY RETAIL RICE : 10 bags 52.5 USD
* PAY WHOLESALE SUGAR : 0 bags 0 USD
* PAY RETAIL SUGAR : 1 bags 3.25 USD
*YOU PAY FOR COFFEE : 1 pots 7.5 USD
*YOU PAY FOR MILK CANS : 0 cans 0 USD
* TOTAL PAY : 63.25 USD
THANK YOU , SEE YOU AGAIN !
* MANAGER : BAXAO XAOKE
* YEAR :2016 , MONTH : 2
* DAY : Sat Feb 13 2016 06:09:54 GMT-0800 (Pacific Standard Time)
-----------
WELCOME TO : ENRIQUE SHOP
* PAY WHOLESALE RICE : 100 bags 400 USD *PAY RETAIL RICE : 0 bags 0 USD * PAY WHOLESALE SUGAR : 0 bags 0 USD * PAY RETAIL SUGAR : 10 bags 32.5 USD *YOU PAY FOR COFFEE : 10 pots 75 USD *YOU PAY FOR MILK CANS : 1 cans 1.75 USD * TOTAL PAY : 509.25 USD THANK YOU , SEE YOU AGAIN ! * MANAGER : BAXAO XAOKE * YEAR :2016 , MONTH : 2
* DAY : Sat Feb 13 2016 06:21:56 GMT-0800 (Pacific Standard Time) * PAY WHOLESALE RICE : 100 bags 400 USD *PAY RETAIL RICE : 0 bags 0 USD * PAY WHOLESALE SUGAR : 0 bags 0 USD * PAY RETAIL SUGAR : 10 bags 32.5 USD *YOU PAY FOR COFFEE : 10 pots 75 USD *YOU PAY FOR MILK CANS : 1 cans 1.75 USD * TOTAL PAY : 509.25 USD THANK YOU , SEE YOU AGAIN ! * MANAGER : BAXAO XAOKE * YEAR :2016 , MONTH : 2
UPDATED 17-FEB-16
PROGRAM 6.
TUỲ THEO SỰ SUY NGHĨ, CHÚNG TA CÓ THỂ TÌM RA NHIỀU CÁCH VIẾT KHÁC NHAU.
QUÝ BẠN CÓ THỂ CÓ CÁCH VIẾT TỐT HƠN NỮA.
ĐÂY LÀ PRORAM RẤT DỄ NHỚ,NGẮN GỌN CÓ KÈM THÊM MÁY LÀM TÓAN CỘNG
PROGRAM 6.
TUỲ THEO SỰ SUY NGHĨ, CHÚNG TA CÓ THỂ TÌM RA NHIỀU CÁCH VIẾT KHÁC NHAU.
QUÝ BẠN CÓ THỂ CÓ CÁCH VIẾT TỐT HƠN NỮA.
ĐÂY LÀ PRORAM RẤT DỄ NHỚ,NGẮN GỌN CÓ KÈM THÊM MÁY LÀM TÓAN CỘNG
CHÚNG TA CÓ THỂ CLICK CANCEL,KHÔNG YÊU CẦU SET ZERO NHƯNG PROGRAM VẪN HOẠT ĐỘNG KHÔNG BỊ TRỞ NGẠI.
Viết phần nầy trong script tags.
var shop = {
greeting :" <span style='color:red'>WELCOME TO : ENRIQUE SHOP</span>" ,
product :"CHÚNG TÔI BÁN RICE VÀ SUGAR VỚI GIÁ SỈ VÀ LẺ \n RICE BAG : 5 lbs \n SUGAR BAG : 2 lbs ",
appreciation :"<span style='color:red'>THANK YOU , SEE YOU AGAIN ! </span>",}
document.write(shop.greeting +"<br>");
alert(shop.product);
var x1 = prompt("OVER 100 BAGS.\n HOW MANY WHOLESALE RICE BAGS YOU WANT?");
var pay1 = parseInt(x1*4.00);
var a1 = pay1;
var x2 = prompt("LESS THAN 100 BAGS.\n HOW MANY RETAIL RICE BAGS YOU WANT?");
var pay2 = parseFloat(x2*5.25);
var a2 = pay2;
var y1 = prompt("OVER 100 BAGS.\n HOW MANY WHOLESALE SUGAR BAGS YOU WANT?");
var pay3 = parseInt(y1*4.00);
var a3 = pay3;
var y2 = prompt("LESS THAN 100 BAGS.\n HOW MANY RETAIL RICE BAGS YOU WANT?");
var pay4 = parseFloat(y2*3.25);
var a4 = pay4;
var tot = a1+a2+a3+a4;
document.write("* <span style='color:blue'>TOTAL PAY : </span>" + tot +" "+ "USD"+ "<br>"+
shop.appreciation + "<br>"+
"* MANAGER : BAXAO XAOKE " + "<br><br>");
function findSum(){
document.getElementById("r1").value = a1
document.getElementById("r2").value = a2
document.getElementById("s1").value = a3
document.getElementById("s2").value = a4
document.getElementById("Total").value = tot
}
Viết phần nầy trong body taga
1-RICE WHOLESALE PAY : <input type="text" size ="5" id ="r1" /><br>
2-RICE RETAIL PAY : <input type="text"size ="5" id ="r2" /><br>
3-SUGAR WHOLESALE PAY : <input type="text"size ="5" id ="s1" /><br>
4-SUGAR RETAIL PAY : <input type="text"size ="5" id ="s2" /><br>
TOTAL PAY : <input type="text" size ="5" id="Total"/>
<span onclick="findSum()">CLICK</span>
OUTPUT RECEIPT OF PROGRAM
WELCOME TO : ENRIQUE SHOP
* TOTAL PAY : 8.5 USD
THANK YOU , SEE YOU AGAIN !
* MANAGER : BAXAO XAOKE
1-RICE WHOLESALE PAY :
2-RICE RETAIL PAY :
3-SUGAR WHOLESALE PAY :
4-SUGAR RETAIL PAY :
TOTAL PAY : CLICK
* TOTAL PAY : 8.5 USD
THANK YOU , SEE YOU AGAIN !
* MANAGER : BAXAO XAOKE
1-RICE WHOLESALE PAY :
2-RICE RETAIL PAY :
3-SUGAR WHOLESALE PAY :
4-SUGAR RETAIL PAY :
TOTAL PAY : CLICK
Để ngăn chận nhầm lẩn khi chọn số lượng
cần mua,chúng ta viết thêm vào program những codes như sau.
var pay1 = parseInt(x1*4.00);
if(x1<=100){pay1=0};//viết thêm
var a1 = pay1;
var pay2 = parseFloat(x2*5.25);
if(x2>100){pay2=0}//viết thêm
var a2 = pay2;
var pay3 = parseInt(y1*4.00);
if(y1<=100){pay3=0};//viết thêm
var a3 = pay3;
var
pay4 = parseFloat(y2*3.25);
if(y2>100){pay4=0}//viế thêm
var a4 = pay4;