Arama butonu
Bu konudaki kullanıcılar: 1 misafir
3
Cevap
316
Tıklama
0
Öne Çıkarma
javascript rastgele sayı gizleme
M
7 yıl (7 mesaj)
Er
Konu Sahibi

<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>




<script>

a = Math.floor(Math.random()*9+1);
b = Math.floor(Math.random()*9+1);
c = Math.floor(Math.random()*9+1);
d = Math.floor(Math.random()*9+1);
e = Math.floor(Math.random()*9+1);

x = Math.floor(Math.random()*5+1);
y = Math.floor(Math.random()*5+1);



document.write("Şifrelenmiş basamak = "+y+","+x);
document.write("<br>");




document.write("üretilen sayı = "+a,b,c,d,e);



document.write("<br>");


document.write("şifrelenmiş hali = ")


if (y==1){
document.write("*"+b,c,d,e);
}

else if (y==2){
document.write(a+"*",c,d,e);
}

else if (y==3){
document.write(a,b+"*",d,e);
}
else if (y==4){
document.write(a,b,c+"*",e);
}
else if (y==5 ){
document.write(a,b,c,d+"*");
}



</script>




</body>
</html>







Arkadaşlar yardım ederminisiniz sadece bir yıldız gizleyebiliyorum, amacım 2 rastgele yıldız gizlemek.





< Bu mesaj bu kişi tarafından değiştirildi mucahitozcantr -- 16 Nisan 2019; 14:24:48 >

Y
7 yıl (470 mesaj)
Yüzbaşı

Olayı doğru anladıysam,
rasgele 2 yıldız gizlemek için:

y = Math.floor(Math.random()*10+1);

olması lazım. C(5,2) = 10 olduğu için. Sonrasında da:

if (y==1){
document.write("**" + c,d,e);
}

else if (y==2){
document.write("*" + b + "*",d,e);
}

else if (y==3){
document.write("*" + b, c + "*",e);
}
else if (y==4){
document.write("*" + b, c, d + "*");
}
else if (y==5 ){
document.write(a + "**" + d, e);
}
else if (y==6){
document.write(a + "*" + c + "*" + e);
}

else if (y==7){
document.write(a + "*" + c, d + "*");
}

else if (y==8){
document.write(a, b + "**" + e);
}
else if (y==9){
document.write(a, b + "*" + d + "*");
}
else if (y==10 ){
document.write(a, b, c + "**");
}



M
6 yıl (7 mesaj)
Er
Konu Sahibi

Teşekkürler



D
6 yıl (34 mesaj)
Er

let firstStar, secondStar, maxNumber = 10, text = "", i;
const oneStar = () => Math.floor(Math.random() * maxNumber + 1);
while (true) {
firstStar = oneStar(), secondStar = twoStar();
if (firstStar !== secondStar) break;
}
for (i = 1; i <= maxNumber; i++) {
text += i === firstStar || i === secondStar ? `* ` : `${i} `;
}
console.log(text);

Alternatif bir kod, belki faydası dokunur.





< Bu mesaj bu kişi tarafından değiştirildi deadspook -- 26 Mart 2020; 2:56:8 >

DH Mobil uygulaması ile devam edin. Mobil tarayıcınız ile mümkün olanların yanı sıra, birçok yeni ve faydalı özelliğe erişin. Gizle ve güncelleme çıkana kadar tekrar gösterme.