can anyone help me with my javascript program?

I

ivor.horton

i've wrote a javascript program to test the equality of the javascript
special values such as: true,false,null,undefined,NaN,0,1. but the
program can't give me the proper answer, can anyone help me with it ?
great thanks. the code is paste as follows.

---------------------------------------------------------------------------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<title>Page Title</title>
<script type="text/javascript" charset="utf-8">
var t={
values:[null,undefined,NaN,0,1,true,false],
length:t.values.length,

result:"",

test:function(){
for(var i=0;i<length;i++){
for(var j=0;j<length;j++){
if(values==values[j]){
result+=values+"=="+values[j]+" : true\n";
}else{
result+=values+"=="+values[j]+" : false\n";
}
}
}

alert(result);
}
};

testSpecialValues.test();

</script>
</head>
<body>

</body>
</html>
 
J

JR

i've wrote a javascript program to test the equality of the javascript
special values such as: true,false,null,undefined,NaN,0,1. but the
program can't give me the proper answer, can anyone help me with it ?
great thanks. the code is paste as follows.

---------------------------------------------------------------------------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
        <head>
                <meta http-equiv="Content-type" content="text/html; charset=utf-8" /

                <title>Page Title</title>
                <script type="text/javascript" charset="utf-8">
                        var t={
                                values:[null,undefined,NaN,0,1,true,false],
                                length:t.values.length,

                                result:"",

                                test:function(){
                                        for(var i=0;i<length;i++){
                                                for(var j=0;j<length;j++){
                                                        if(values==values[j]){
                                                                result+=values+"=="+values[j]+" : true\n";
                                                        }else{
                                                                result+=values+"=="+values[j]+" : false\n";
                                                        }
                                                }
                                        }

                                        alert(result);
                                }
                        };

                        testSpecialValues.test();

                </script>
        </head>
        <body>

        </body>
</html>


Hi,
This is crazy, but here it is:

var t = {
values: [null, undefined, NaN, 0, 1, true, false],
test: function () {
var v = this.values, i, j,
len = v.length, ret = '';
for (i = 0; i < len; i++) {
for (j = 0; j < len; j++) {
if (v == v[j]) {
ret += v +" == " +v[j] +" : true\n";
} else {
ret += v +" == " +v[j] +" : false\n";
}
}
}
return ret;
}
};

window.alert(t.test());

Cheers,
Joao Rodrigues
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top