I'm beginning javascript and i do some exercise to train my self, but i've a
problem.
My code had to ask the time to the user and give the time one seconde after
the time entered.
And my code shows my always "temps erroné" (that mean ~wrong time).
Here's my code :
這讓用戶的時間我的代碼不工作
var hour = Number(prompt("heure actuelle?"));
var minute = Number(prompt("minute actuelle?"));
var seconde = Number(prompt("seconde actuelle?"));
//這個功能就像是一個控制,如果輸入的時間是錯誤的功能 是假
function isTimeValid(hour, minute, seconde){
if((hour >= 24) || (hour < 0)) {
return false
}
if((minute < 0) || (minute >= 60)) {
return false
}
if((seconde >= 60) || (seconde < 0)) {
return false
}
else {
return true
}
}
此功能修改時間
function displayNextHour(hour, minute, seconde){
if((seconde >= 0) && (seconde < 59)) {
seconde++;
} else if(seconde === 59) {
seconde = 0
minute++
}
if(minute === 60) {
minute = 0
hour++
}
if(hour === 24) {
hour = 0
}
var time = "Il est " + hour + "h " + minute + "m " + seconde + "s";
return time
}
最後一部分午餐功能
if(isTimeValid()){
console.log(displayNextHour(hour, minute, seconde))
}else{
console.log("temps erroné")
}
所以,如果你能幫助我,這將是對我很大的幫助,我的JavaScript學習:D
請考慮選擇相關標題以及使用相關標籤。 – Berger
Java!= javascript –