Skip to content

Instantly share code, notes, and snippets.

@antronic
Created July 10, 2018 05:54
Show Gist options
  • Save antronic/6a42bac55a299ea2fe970c57bf73416e to your computer and use it in GitHub Desktop.
Save antronic/6a42bac55a299ea2fe970c57bf73416e to your computer and use it in GitHub Desktop.
function check_word(msg) {
let temp = msg.toLowerCase()
temp = temp.replace(' the', '')
temp = temp.split(' ')
console.log(temp)
let turn = -1
let device = 0
if (temp[0] === 'turn') {
if (temp[1] === 'on') {
turn = 1
}
else if (temp[1] === 'off') {
turn = 0
}
if (temp[2] === 'red' && temp[3] === 'light') {
device = 1
}
}
// 2
// 1
return {operation: turn, device}
}
const text = process.argv.splice(2).join(' ')
const result = check_word(text)
// convert JSON to string
const result_str = JSON.stringify(result)
if (result.operation === 0) {
console.log('จงปิด')
} else if (result.operation === 1) {
console.log('เปิดดิ!')
}
if (result.device === 1) {
console.log('หลอดไฟ สีแดง~')
} else {
console.log('เครื่องไหนว้ะ')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment