我主要是想寫個解方程式的程式碼
``` var time_val; var go_timer; var stop_time = 0; function add_zero(num, digit) { let numString = String(num) while (numString.length < digit) { numString = "0" + numString } return numString } go_timer = new Date(); time_val = setInterval(() => { let temp_timer = new Date().getTime() - go_timer.getTime(); let day = add_zero(Math.floor(temp_timer / 1000 / 60 / 60 / 24), 2); let hours = add_zero(Math.floor(temp_timer / 1000 / 60 / 60) % 24, 2); let minutes = add_zero(Math.floor(temp_timer / 1000 / 60) % 60, 2); let seconds = add_zero(Math.floor(temp_timer / 1000 % 60), 2); let milliseconds = add_zero(temp_timer % 1000, 3); var timers = [day, hours, minutes, seconds, milliseconds]; console.log(timers[0] + "天\n" + timers[1] + "時\n" + timers[2] + "分\n" + timers[3] + "秒\n" + timers[4] + "毫秒"); }, 1)
![](https://i.imgur.com/fcb92uZ.jpg) 手錶上運行失敗
用node.js試試看
你有興趣開發小米手環嗎 https://www.bandbbs.cn/ ![](https://i.imgur.com/QyCaIix.png)
#我要做一個自動解方程 主控臺 --- "Error solving equation: Invalid left hand side of assignment operator = (char 5) Return:a + 27 = 0" --- ```<!DOCTYPE html> <html> <head> <meta name="description" content="math.js | basic usage"> <title>math.js | basic usage</title> <script src="https://unpkg.com/mathjs/lib/browser/math.js"></script> </head> <body> <script> function solveEquation(equationString, variableRange = { start: -10, end: 10, step: 0.1 }) { if (typeof equationString !== 'string') { throw new Error('Equation must be a string'); } const equation = equationString.replace(/\s/g, ''); const variables = equation.match(/[a-zA-Z]+/g); if (!variables) { throw new Error('No variables found in equation'); } const parser = math.parser(); variables.forEach(variable => { parser.evaluate(`${variable} = ${variableRange.start}:${variableRange.step}:${variableRange.end}`); }); let result; try { result = parser.evaluate(equation); } catch (error) { throw new Error('Error solving equation: ' + error.message + "\nReturn:" + equationString); } return result; } const equationString = "a + 27 = 0"; try { const result = solveEquation(equationString); console.log("方程的解为:", result); } catch (error) { console.error(error.message); } </script> </body> </html>
然後作為一個計時器可是總是顯示undefined 小米手環文件 https://cdn.discordapp.com/attachments/1132882463522312204/1132987644255670322/helloworld_pro.bin ``` var time_val; var go_timer; var stop_time = 0; function add_zero(num, digit) { let numString = String(num) while (numString.length < digit) { numString = "0" + numString } return numString } function timers() { if (true) { let temp_timer = new Date().getTime() - go_timer; let day = add_zero(Math.floor(temp_timer / (24 * 60 * 60 * 1000)), 2); let hours = add_zero(Math.floor((temp_timer % (24 * 60 * 60 * 1000)) / (60 * 60 * 1000)), 2); let minutes = add_zero(Math.floor((temp_timer % (60 * 60 * 1000)) / (60 * 1000)), 2); let seconds = add_zero(Math.floor((temp_timer % (60 * 1000)) / 1000), 2); let milliseconds = add_zero(temp_timer % 1000, 3); return [day, hours, minutes, seconds, milliseconds]; } } go_timer = new Date().getTime(); time_val = setInterval(() => { var time = timers(); console.log(time[0] + "天\n" + time[1] + "時\n" + time[2] + "分\n" + time[3] + "秒\n" + time[4] + "毫秒"); }, 1); /* undefined天 undefined時 undefined分 undefined秒 undefined毫秒 */
我要做一個檢測undefined值的 代碼: data = { highscore: 0, localStorage: null, footsteps: 0, start: 0, checkin: 0, health: 6, fed: 0, birthday: Date.now(), feedCount: 0, pet_push_time: 0, old_pet_mod: false, old_pet_birthday: Date.now(), old_pet_days: -1, old_pet_pet_push_time: 0, old_pet_feedCount: 0, back_HPbox: 0, } function undefined_test(val) { if (val === undefined){ return 1 } else { return 0 } //1表示這個值未定義 } undefined_test(data.test); 他不會回傳1
你的轉職路上,還缺少一份自學作業包!寫完這幾包,直接拿作品去面試上班!
本論壇另有附設一個 LINE 新手發問&交流群組!歡迎加入討論!