我試圖在存儲在「name」var中的提示中詢問用戶名,如果用戶什麼都不輸入,它會隨機選擇來自存儲在randomName數組中的數組的值。但它不返回數組中輸入的值或任何內容,它返回的是「您的名字是」。爲什麼?如何獲取此提示的值並將其放入if/else語句
這是迄今爲止
var name=prompt("Please enter a usename");
if(name===" "){
var randomName=["Spill Cramer","Oberon Gorgeous","Pointy Binge","Lord Inquiry","Lower Salmon","Auk Cheeks","Minty Lub","Sonore Dim","African Hernia","Squares Pine","Promise Waterpolo","Cucumber Wizard","Tactful Rampallian","Mars Pawn","Usually Dispatch","Close Baffled","Adaptive Mugger","Involved Neuron","Position Stash","Buttercream Oxidant","Bus Hootenany","Small PHP","Copernicium Hematoma","Nostalgic Relay","Wetsuit Swinhoe"]
var rand=randomName[Math.floor(Math.random()*randomName.length)];
if(rand===0){
alert("Your name is Overfilled Lemon");
}
else{
alert("Your name is "+rand)
}
}
else{
alert("Your name is ",name);
};
如果用戶什麼都不輸入,那麼'name'將等於'''',而不是''''' – Hamms