限时优惠活动
亲爱的苦力吧用户,我们为了回馈新老用户一直以来的鼎力支持,即日起(2025-02-06至2025-03-06)凡是购买苦力吧VIP/充值K币的新老用户,都直接可获得买一送一的优惠馈赠。例如:购买一个月的VIP会员可直接获得两个月的VIP会员;充值100K币可直接获得200K币,以此类推!有任何疑问可联系在线客服,感谢各位用户对苦力吧素材的信任与厚爱,我们将一如既往的给大家上新更多优质的素材源码,祝大家开工大吉、工作顺利、心想事成。

JavaScript实现的英文单词拼字游戏

所属分类: 网页特效-抽奖&游戏    2024-12-02 09:24:02

JavaScript实现的英文单词拼字游戏 ie兼容6
 查看演示  登录后下载 温馨提示
登录会员即可享受免费下载
 我要建站

JavaScript实现的英文单词拼字游戏(共4个文件)

    • index.html
    • style.css

使用方法

const wordText = document.querySelector(".word"),
hintText = document.querySelector(".hint span"),
timeText = document.querySelector(".time b"),
inputField = document.querySelector("input"),
refreshBtn = document.querySelector(".refresh-word"),
checkBtn = document.querySelector(".check-word");

let correctWord, timer;

const initTimer = maxTime => {
    clearInterval(timer);
    timer = setInterval(() => {
        if(maxTime > 0) {
            maxTime--;
            return timeText.innerText = maxTime;
        }
        alert(`时间到了! ${correctWord.toUpperCase()} 是正确的单词`);
        initGame();
    }, 1000);
}

const initGame = () => {
    initTimer(30);
    let randomObj = words[Math.floor(Math.random() * words.length)];
    let wordArray = randomObj.word.split("");
    for (let i = wordArray.length - 1; i > 0; i--) {
        let j = Math.floor(Math.random() * (i + 1));
        [wordArray[i], wordArray[j]] = [wordArray[j], wordArray[i]];
    }
    wordText.innerText = wordArray.join("");
    hintText.innerText = randomObj.hint;
    correctWord = randomObj.word.toLowerCase();;
    inputField.value = "";
    inputField.setAttribute("maxlength", correctWord.length);
}
initGame();

const checkWord = () => {
    let userWord = inputField.value.toLowerCase();
    if(!userWord) return alert("Please enter the word to check!");
    if(userWord !== correctWord) return alert(`哎呀! ${userWord} 不是正确的单词`);
    alert(`恭喜! ${correctWord.toUpperCase()} 是正确的单词`);
    initGame();
}

refreshBtn.addEventListener("click", initGame);
checkBtn.addEventListener("click", checkWord);

站长提示:
1. 苦力吧素材官方QQ群:950875342
2. 平台上所有素材资源,需注册登录会员方能正常下载。
3. 会员用户积极反馈网站、素材资源BUG或错误问题,每次奖励2K币
4. PHP源码类素材,如需协助安装调试,或你有二次开发需求,可联系苦力吧客服。
5. 付费素材资源,需充值后方能下载,如有任何疑问可直接联系苦力吧客服
相关资源 / 抽奖&游戏

jquery基于json文件中显示抽奖名单数据在线抽奖代码

一款姓名+手机号码滚动抽奖特效代码,抽奖名单读取本地的data.json文件,点击“开始抽奖”后,开始滚动,点击“停止”后显示中奖名单。
  抽奖&游戏
 3340  0

jquery无缝滚动在线抽奖机老虎机特效

一款模拟老虎机游戏机抽奖代码,停止和开始均为分开控制了,点击开始按钮,三位数字立即转动,按停止按钮可抽奖。
  抽奖&游戏
 7866  0

jquery响应式图片滚动随机抽奖特效代码

jquery响应式图片滚动随机抽奖特效代码
  抽奖&游戏
 5388  0

jquery随机格子抽奖特效代码

通过鼠标点击抽奖按钮多个奖品格子依次随机闪烁摇奖过程,最终抽奖结束奖品格子闪烁摇奖停止。
  抽奖&游戏
 2529  0

评论数(0) 回复有机会获得K币 用户协议

^_^ 还没有人评论,快来抢个沙发!
😀
  • 😀
  • 😊
  • 😂
  • 😍
  • 😑
  • 😷
  • 😵
  • 😛
  • 😣
  • 😱
  • 😋
  • 😎
  • 😵
  • 😕
  • 😶
  • 😚
  • 😜
  • 😭
发表评论