JS:地铁报站

来源:互联网 发布:iphone5s手机壳淘宝 编辑:程序博客网 时间:2024/04/28 01:07

自从学习JS之后,遇到什么都想着用JS解决试试看,比如昨天坐地铁听到报站,就觉得可以用JS解决一下。


JS:

//站点名称var arr = ["A","B","C","D","E"];//起始站点var index = 0;function bus(){    console.log("Current station is "+ arr[index] +", the next station is "+ arr[index+1] + ".");    index++;    if(index === arr.length-1){      arr.reverse();      index = 0;    }}//每到一个站点,执行一次bus()即可

DEMO:Bus Broadcast

0 0
原创粉丝点击