Advertisement
WILDAN_IZZUDIN

[JS] TTS GAME

Jan 30th, 2023
724
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const axios = require('axios')
  2. const randomArray = (arr) => {
  3.    return arr[Math.floor(Math.random() * arr.length)]
  4. }
  5.  
  6. const questions = async () => {
  7.    const res = await axios.get('https://json.nxr.my.id/c/hXBPY')
  8.    return res.data
  9. }
  10.  
  11. var Set = {
  12.    started: true,
  13.    attempt: 0,
  14.    hint: randomArray(['A', 'B', 'C', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']),
  15.    ans: '',
  16.    question: []
  17. }
  18.  
  19. const flow = setInterval(async () => {
  20.    Set.attempt += 1
  21.    if (Set.started) {
  22.       Set.started = false
  23.       const json = await (await questions()).find(v => v.jawaban.startsWith(Set.hint))
  24.       Set.ans = json.jawaban
  25.       Set.question.push(json)
  26.       console.log(`Question : ${Set.attempt}. ${json.pertanyaan} (${json.jawaban})`)
  27.    } else {
  28.       const ans = Set.ans.split`` [Set.ans.split``.length - 1]
  29.       const json = await (await questions()).find(v => v.jawaban.startsWith(ans))
  30.       Set.ans = json.jawaban
  31.       Set.question.push(json)
  32.       console.log(`Question : ${Set.attempt}. ${json.pertanyaan} (${json.jawaban})`)
  33.    }
  34.    if (Set.attempt >= 10) {
  35.       clearInterval(flow)
  36.       console.log(Set.question)
  37.    }
  38. }, 3000)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement