JavaScript ile 1-100 arası sayılardan 3’e ya da 5’e tambölünen sayıları ekranda yazdıran, aynı zamanda bu sayıların toplamınıda ekranda gösteren örneğe ait kodlar.
for1.js dosyası
1 2 3 4 5 6 7 8 9 10 11 12 13 | // JavaScript Document var toplam=0; for(var i=1;i<100;i++) { if(i%3==0 ||i%5==0) { toplam+=i; document.write(i+"<br>"); } } document.write("Toplam :"+toplam); |
index.html dosyası:
1 2 3 4 5 6 7 8 9 10 11 12 13 | <!doctype html> <html> <head> <meta charset="utf-8"> <title>Untitled Document</title> </head> <body> <script src="for1.js"></script> </body> </html> |