日期:2014-05-18  浏览次数:20449 次

我是菜鸟,请问这个是什么?
1 这个是什么
function funTouch(){

var a = 10;
var b = 20;
var c = 10;
alert(a = b);
alert(a == b);
alert(a == c);

输出什么结果

2、一个竹竿长39cm,分别在竹竿的第9,15,23,33处有一只蚂蚁。前提条件:蚂蚁朝哪个方向爬不定,只会沿直线朝一个方向爬行,在碰到其它蚂蚁后转向相反方向爬行,假设蚂蚁的爬行速度为1cm/s,问:
1.所有蚂蚁爬出竹竿的最短时间是多少?请作简单解释。
2.所有蚂蚁爬出竹竿的最长时间是多少?请作简单解释。
答:


------解决方案--------------------
这都是什么?
------解决方案--------------------
1 这个是什么 
function funTouch(){ 

var a = 10; 
var b = 20; 
var c = 10; 
alert(a = b); 
alert(a == b); 
alert(a == c); 
}
输出什么结果 
----------------------------
编译错误,alert对话框里应是字符串类型.
------解决方案--------------------
JScript code
function   funTouch(){ 
var   a   =   10; 
var   b   =   20; 
var   c   =   10; 
alert(a   =   b);//执行a=b后输出a的值~也就是20 
alert(a   ==   b); //输出true
alert(a   ==   c); //输出false
}

------解决方案--------------------
呵呵
------解决方案--------------------
第二题
最快16秒
最慢33秒~把相遇会掉头的蚂蚁看作穿行而过就行了,实际是一样的。
------解决方案--------------------
HTML code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>蚂蚁爬行演示</title>
    <style type="text/css">
    td{
        border:1px solid black;
    }
    </style>
</head>
<body>
<script type="text/javascript">
function Bamboo(length,row){
    Bamboo.instance=this;
    this.ants=[];
    this.length=length;
    this.row=row;
    for(var i=0;i<=length;i++){
        var td=document.createElement("td");
        row.appendChild(td);
    }
    this.start=function(){
        setInterval("Bamboo.instance._doWalk()",1000);
    }
    this._doWalk=function(){
        for(var i=0,j=this.ants.length;i<j;i++){
            if(!this.ants[i].stop)this.ants[i].walk();
        }
    }
}
function ant(bamboo,position,direction){
    this.bamboo=bamboo;
    bamboo.ants.push(this);
    this.position=position;
    this.direction=direction;
    this.stop=false;
}
ant.prototype.walk=function(){
    this.bamboo.row.cells[this.position].innerHTML="";
    if(this.direction){
        this.position++;
    }else{
        this.position--;
    }
    if(this.position<0){
        this.stop=true;
        return this.bamboo.row.cells[0].innerHTML="";
    }
    if(this.position>this.bamboo.length){
        this.stop=true;
        return this.bamboo.row.cells[this.position-1].innerHTML="";
    }
    this.bamboo.row.cells[this.position].innerHTML="*";
}
window.onload=function(){
    var table=document.getElementById("bamboo");
    var tr=document.createElement("tr");
    table.appendChild(tr);
    for(var i=0;i<=39;i++){
        var td=document.createElement("td");
        tr.appendChild(td);
        td.innerHTML=i;
    }
    tr=document.createElement("tr");
    table.appendChild(tr);
    var bamboo=new Bamboo(39,tr);
    var ant1=new ant(bamboo,9,true);
    var ant2=new ant(bamboo,15,true);
    var ant3=new ant(bamboo,23,false);
    var ant4=new ant(bamboo,33,false);
    bamboo.start();
}
</script>
<table><tbody id="bamboo"></tbody></table>
</body>
</html>

------解决方案--------------------
1题: 20 true false
2题:就不知道了,伤脑筋