JavaScript loop alma

Katılım
1 Temmuz 2017
Mesajlar
1.677
Çözümler
3
Daha fazla  
Cinsiyet
Erkek
Meslek
Haçker
Öncelikle selamlar. Biz derste gördüğümüz bir şeyi yapmak istiyoruz ama kodlama görmediğimiz için yapamıyoruz. Biz de JS ile yapmaya çalıştık ama bir adım var orayı yapamadık. Hocanın verdiği şeyi yazsam ona göre giriş seviyesinde bir kodlama yapar mısınız?

Başla.
X oku.
N oku.
X yaz.
X = X+1
Eğer x<n ise 4. adıma dön.
Bitir.
 
Merhaba, böyle bir şey mi istiyordunuz?

HTML:
<form id="Vegas" action="" method="POST">
    <input type="number" name="x" id="X">
    <input type="number" name="n" id="N">
    <button type="submit">Gönder</button>
</form>


<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script>
    $("#Vegas").on("submit", function(e) {
        e.preventDefault();
        $.ajax({
            type: $(this).attr('method'),
            url: $(this).attr('action'),
            data: $(this).serialize(),
            error: data => {
                console.log('Hata');
                console.log(data);
            }
        }).done(e => {
            var x = document.getElementById("X").value;
            var n = document.getElementById("N").value;
            for (let x = 0; x < n; x++) {
                console.log(x);
                x = x + 1;
                console.log(x);
            }
        })
    })
</script>
 
Merhaba, böyle bir şey mi istiyordunuz?

HTML:
<form id="Vegas" action="" method="POST">
    <input type="number" name="x" id="X">
    <input type="number" name="n" id="N">
    <button type="submit">Gönder</button>
</form>


<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script>
    $("#Vegas").on("submit", function(e) {
        e.preventDefault();
        $.ajax({
            type: $(this).attr('method'),
            url: $(this).attr('action'),
            data: $(this).serialize(),
            error: data => {
                console.log('Hata');
                console.log(data);
            }
        }).done(e => {
            var x = document.getElementById("X").value;
            var n = document.getElementById("N").value;
            for (let x = 0; x < n; x++) {
                console.log(x);
                x = x + 1;
                console.log(x);
            }
        })
    })
</script>
Hata veriyor.
 
Hata nedir? Çalışması lazım.

1641078265972.png
 
Merhaba, böyle bir şey mi istiyordunuz?

HTML:
<form id="Vegas" action="" method="POST">
    <input type="number" name="x" id="X">
    <input type="number" name="n" id="N">
    <button type="submit">Gönder</button>
</form>


<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script>
    $("#Vegas").on("submit", function(e) {
        e.preventDefault();
        $.ajax({
            type: $(this).attr('method'),
            url: $(this).attr('action'),
            data: $(this).serialize(),
            error: data => {
                console.log('Hata');
                console.log(data);
            }
        }).done(e => {
            var x = document.getElementById("X").value;
            var n = document.getElementById("N").value;
            for (let x = 0; x < n; x++) {
                console.log(x);
                x = x + 1;
                console.log(x);
            }
        })
    })
</script>
Ek olarak giriş seviyesinde olursa.
Hata nedir? Çalışması lazım.

Eki Görüntüle 1258635
Java olarak mı yazdınız acaba?
 
Hata nedir? Çalışması lazım.

Eki Görüntüle 1258635
Ajax ve php server tarafında çalışmalı. Arkadaş da local server yok. Bu sebeple hata veriyordur.

Alttaki kod işini görmesi lazım. Mobilde olduğum için test etmedim.
JavaScript:
let x = prompt("x değerini giriniz");
let n = prompt("n değerini giriniz");

do{
    console.log(x);
    x+=1;
}while(x<n);
 

Technopat Haberler

Geri
Yukarı