Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
    <head><title>循序搜尋</title></head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<body></body>
</html>
 
$().ready(function(){
    var datas=[8,4,1,3,9,5,6,7,2,0];
    var i=0;
    var found=false;
    var n=window.prompt("請輸入要搜尋的數字");
    for(i=0;i<datas.length;i++){
        if (datas[i]==n){
            window.alert("index「"+i+"」是要找的數字:"+n);
            found=true;
            break;
        }
    }
    if (found===false) window.alert("找不到要找的數字:"+n);
});
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
yaoyao34pro
0viewers