zoukankan      html  css  js  c++  java
  • Javascript---- 练习十(Math自带函数)

    代码:

    <!DOCTYPE html>
    <html>
    
    	<head>
    		<meta charset="UTF-8">
    		<title></title>
    	</head>
    
    	<body>
    		<script type="text/javascript">
    			//1.Date()与new Date()的区别
    
                 
              /*
    			var d1 = Date();
    			var d2 = new Date();
    			console.log("d1:"+d1);
    			console.log("d2:"+d2);
    			//console.log("d1.getTime():"+d1.getTime());//直接报错,没有date对象的操作函数
    			console.log("d2.getTime():"+d2.getTime());//可以使用date的其他函数获取相应数据
                console.log(Date("fewfwef"));
                  
                  博客园:
                          Date()直接返回当前时间字符串,不管参数是number还是任何string
                          而new Date()则是会根据参数来返回对应的值,无参数的时候,返回当前时间的字符串形式;有参数的时候返回参数所对应时间的字符串。new Date()对参数不管是格式还是内容都要求,且只返回字符串,
                */
    
                
    
    			//2.var date =new Date("2016-05-31 08:00")与var date =new Date("2016/05/31 08:00")的区别
                  
                   var date1 =new Date("2016-05-31 08:00");
                   var date2 =new Date("2016/05/31 08:00");
    
                  /* console.log("date1:"+date1);
                   console.log("date2:"+date2);*/
    
    
    
    
    			//3.console.log( 0.1 + 0.2 )为什么会输出 0.30000000000000004
    
                /*
                   js 特有的精确度问题,
    
                 
                */
    
    
    			//4.请解析以下代码为什么会输出1,2,3
    			//						console.log("1");//1
    			//						setTimeout(function() {
    			//							console.log("3")
    			//						}, 0);
    			//						console.log("2");
    
                    /*
                        setTimeout被延迟执行,因为执行他会导致其他js运行暂停
    
                    */
     
    
    
    			//5.请解释下面代码运行的结果
    				/*	var a = "one"; 
    					if(a) { //true
    						console.log(a == true); //false
    					} else {
    						console.log("Melon");//melon
    					}*/
    					/*
                       a的值存在,不为空不为零不为undefied,所以是true
                       a 和 true 比较,true转为字符串,两者比较值不相等
    					*/
    
    
    
    
    
    			//6.请分析console.log(1 + - + + + - + 1)的结果为什么等于2
                    /*
                       console.log(1 + (- (+ (+ (+ (- (+ 1)))))));
                    */
    
    			//7.Math.round、parseInt、Math.floor和Math.ceil的区别
    			/*
    			console.log("Math.round(1.4):"+Math.round(1.4));
    			console.log("Math.round(1.5):"+Math.round(1.5));
    			console.log("Math.round(1.6):"+Math.round(1.6));
    
    			console.log("parseInt(1.4):"+parseInt(1.4));
    			console.log("parseInt(1.5):"+parseInt(1.5));
    			console.log("parseInt(1.6):"+parseInt(1.6));
    
    			console.log("Math.floor(1.4):"+Math.floor(1.4));
    			console.log("Math.floor(1.5):"+Math.floor(1.5));
    			console.log("Math.floor(1.6):"+Math.floor(1.6));
    
    			console.log("Math.ceil(1.4):"+Math.ceil(1.4));
    			console.log("Math.ceil(1.5):"+Math.ceil(1.5));
    			console.log("Math.ceil(1.6):"+Math.ceil(1.6));
    			*/
    
    
    			/*
                 1、Math.round:四舍五入
                 2、parseInt 取整
                 3、Math.floor 向下取整
                 4、Math.ceil 向上取整
    
    			*/
    
    
    
    
    			//8.计算出计算机从一加到一百万所用的时间
    			//提示,获取当前的时间戳    (new Date()).getTime()
    
                  
               /*   var date1  = new Date();
                  
                  sum = 0;
                  for(var i = 0;i < 100000000;i++){
                     sum += i;
                  }
    
                  var date2 = new Date();
    
    
                  console.log("date2-date1:"+(date2-date1));*/
    
    
    
    
    
    
    			//9.输出从小到大排序好的五个不重复的随机整数,范围[10-23) (0-13)+10
    
                 /*var a = [];
                 var n = 0;
                 while(n<5){
                 	var num = parseInt(Math.random()*13)+10;
                 	var c = 0;
    	             for(var i = 0;i< n;i++){
    	             	if(num != a[i]){
                        c++;
    	             	}
    
    	             }
    	             if(c==n){
    	             	n++;
    	                a.push(num);
    	             }
                 }
    
                  var arr  = a.sort(function(a,b){
                  	return a-b;
                  })
    
                 console.log(arr);
    */
    
    
    			//10.实现一个必须大于当前时间的倒计时(X天X时X分X秒)
    
                 /*setInterval(setVal,1000);
    
                 var t = "2017,8,25";
                 var ts = t.split(",")
    
                 var date2 = new Date(t);
    
    
    
                 function setVal(){
    
                   var date1 = new Date();
                
    
        
                     var interval = parseInt(parseInt(date2.getTime())-parseInt(date1.getTime()));
    
                     var day = parseInt(interval/1000/60/60/24);
                
                    
                  
    
                     var hour = parseInt((interval-day*1000*60*60*24)/60/60/1000);
    
                     var minute = parseInt((interval-day*1000*60*60*24-hour*60*60*1000)/60/1000);
    
                     var second = parseInt((interval-day*24*60*60*1000-hour*60*60*1000-minute*60*1000)/(1000)%(60*60));
                     
                     var s = "距离"+ts[0]+"年"+ts[1]+"月"+ts[2]+"日"+"还有"+day+"天"+hour+"时"+minute+"分"+second+"秒";
    
    
                     document.querySelector("body").innerText = s;
                  }*/
    
    		</script>
    	</body>
    
    </html>
    

      

  • 相关阅读:
    性能测试理论知识
    接口测试笔试题
    测试计划与测试报告
    java基础面试题
    软件测试人员必备的linux命令
    tomcat各目录(文件)作用
    常见的面试题
    LoadRunner中怎么设置密码参数化与用户名关联
    数据库索引总结(二)
    数据库索引总结(一)
  • 原文地址:https://www.cnblogs.com/SunlikeLWL/p/7240805.html
Copyright © 2011-2022 走看看