我正在編寫一個程序,允許用戶只能查看4星評級的酒店。每當我運行此代碼時,我都會繼續獲取數組中的所有對象,而不僅僅是'希爾頓'和'假日酒店'。我究竟做錯了什麼?謝謝。根據用戶輸入的警報顯示數組等級
var hotels = ['Marriot', 'Hilton', 'Double Tree', 'Holiday Inn']
var visitorRating = ['0 starts', '4 stars', '1 star', '4 stars']
var seeHotels = prompt("Would you like to see all of the hotels whose ratings are 4 stars?");
var fourStars = e;
for(var e = 0; e < visitorRating.length; e++){
if(visitorRating[e].indexOf("4 stars"))
document.write(hotels[e] + ' ' + visitorRating[e])
}
}