Skip to content

Commit 01753de

Browse files
committed
add functions to validate count input and mspf input while push prepare btn, if invalid , it will trigger window.alert pops up
1 parent 2cda1fa commit 01753de

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

js/test.js

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -102,38 +102,31 @@ function allDisable(except){
102102
}
103103

104104
function isCountInputValid(countNum){
105-
console.log(countNum);
106-
if(countNum < 5 || countNum > 500){
105+
if(!countNum || countNum < 5 || countNum > 500){
107106
return null;
108107
}
109108
return countNum;
110109
}
111110

112111
function isMspfInputValid(mspfInput){
113-
console.log(typeof mspfInput);
114-
if(mspfInput < 5 || mspfInput > 1000){
112+
if(!mspfInput || mspfInput < 5 || mspfInput > 1000){
115113
return null;
116114
}
117115
return mspfInput;
118116
}
119117

120-
function errDisaply(entryNum , mspfNum){
121-
const errInput = document.getElementById('err');
122-
if(entryNum === null || mspfNum === null){
123-
errInput.textContent = 'Input Invalid';
118+
function inputInvalid(entryNum , mspfNum){
119+
if(!entryNum || !mspfNum){
124120
return true;
125121
}
126-
// if(){
127-
// mspfInput.border = "red solid 1px";
128-
// return true;
129-
// }
130122
return false;
131123
}
132124

133125
function prepareForRun(){
134126
one.entryNum = isCountInputValid( parseInt(countInput.value, 10) );
135127
one.milliSecPerFrame = isMspfInputValid( parseInt(mspfInput.value, 10));
136-
if( errDisaply(one.entryNum , one.milliSecPerFrame) ){
128+
if( inputInvalid(one.entryNum , one.milliSecPerFrame) ){
129+
window.alert('圖形數量、ms per frame 輸入錯誤,\n請重新輸入')
137130
return
138131
}
139132
one.generateElements();

0 commit comments

Comments
 (0)