Closed Javascript problem

Status
Not open for further replies.

BakalBote

Eternal Poster
Joined
Jul 3, 2016
Posts
1,777
Reaction
445
Points
481
paghingi po ng code.
ito po problem

var a
var b
var c

var a = random number up to 3
print (a)

var b = random number up to 3
👉 if (b) is equal to (a)
👉👉 generate another (b)
👉 else if (b) is not equal to (a)
👉👉 print (b)

var c = random number up to 3
👉 if (c) is equal to (a) or (b)
👉👉 generate another (c)
👉 else if (c) is not equal to (a) and (b)
👉👉 print (c)


Thank po sa makaka tulong na mga master.
 
try mo paps di ko pa na run yan isip2 lng haha baka my error
JavaScript:
function rnd(){
    var limit = 3;
    return Math.floor(Math.random() * limit) + 1;
}
var a;
var b;
var c;
a = rnd();
console.log(a);
while(b != a && b != undefined){
    b = rnd();
}
console.log(b);
while(c != a && c != b && c != undefined){
    b = rnd();
}
console.log(c);
 
try mo paps di ko pa na run yan isip2 lng haha baka my error
JavaScript:
function rnd(){
    var limit = 3;
    return Math.floor(Math.random() * limit) + 1;
}
var a;
var b;
var c;
a = rnd();
console.log(a);
while(b != a && b != undefined){
    b = rnd();
}
console.log(b);
while(c != a && c != b && c != undefined){
    b = rnd();
}
console.log(c);

ayaw boss. undefined lang ung dalawa
 

Attachments

haha natawa ako sa first code ko mali talaga yun haha ito try mo
JavaScript:
    function rnd(){
        var limit = 3;
        return Math.floor(Math.random() * limit) + 1;
    }
    var a = rnd();
    var b = null;
    var c = null;

    console.log("a",a);

    while(true){
        b = rnd();
        if(b !== a && b !== null){
           break;
        }
    }
    console.log("b",b);

    while(true){
        c = rnd();
        if(c !== a && c !== b && c !== null){
           break;
        }
    }
    console.log("c",c);
 
or ito mas simple
JavaScript:
    function rnd(){
        var limit = 3;
        return Math.floor(Math.random() * limit) + 1;
    }
    var a = rnd();
    var b = rnd();
    var c = rnd();

    console.log("a",a);

    while(true){
        b = rnd();
        if(b !== a){
           break;
        }
    }
    console.log("b",b);

    while(true){
        c = rnd();
        if(c !== a && c !== b){
           break;
        }
    }
    console.log("c",c);
 
Status
Not open for further replies.
Back
Top