user_input = "";
answer = "";
Array.greeting = ["hi", "hello"]
Array.names = ["john","james"]
user_input = document.getElementById('user_input').value.toLowerCase();
document.getElementById('text_input').innerHTML = user_input;
documnet.getElementById('say_something').innerHTML = say;
if(""){}
else{}
if(Array.greeting.includes(user_input) > 0){
say = "Hello";
}
if(Array.names.includes(user_input) > 0){
say = "User";
}
這就是我理解和啓動並運行正確的輸出,但我怎麼可以使用輸入「喂約翰」,並獲得「你好用戶」的輸出與烤出來的數組?如何檢查字符串的一部分是否在數組中?
'documnet'是一個錯字。當該線路運行時'say'沒有被定義。 – Xufox
你意識到你正在向'Array'對象添加屬性,而不是聲明變量?假設你知道這一點,你爲什麼要採取這種方法? –
這實際上並不是代碼的一部分,而是匆忙做出來的。 'if(Array.greeting.includes(user_input)> 0){if} =「Hello」; (Array.names.includes(user_input)> 0){ } if =「User」; }' 我需要將這兩個結合起來,以便答案既可以來自兩者,也可以來自組合目標。 –