๐Ÿ”’ Closed Javascript problem

Status
Not open for further replies.

BakalBote

Eternal Poster
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

  • Screenshot_20191002-190446.webp
    Screenshot_20191002-190446.webp
    21.6 KB · Views: 13
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.

About this Thread

  • 4
    Replies
  • 393
    Views
  • 2
    Participants
Last reply from:
Flavored

Online now

Members online
560
Guests online
986
Total visitors
1,546

Forum statistics

Threads
2,275,071
Posts
28,960,437
Members
1,233,568
Latest member
Watchinnm
Back
Top