第十三届蓝桥杯国赛 Web 前端组(大学组) 真题练习及答案解析

本文为第十三届蓝桥杯国赛Web前端组的真题练习及答案解析,涵盖数组方法、flex布局、DOM操作、权限管理等考点。通过实际题目,解析了如何利用splice()方法处理数组,运用flex布局解决界面展示,使用js操作和eval()方法进行计算,以及实现递归和深度优先遍历在商城管理系统中的应用。
摘要由CSDN通过智能技术生成

【真题练习】分一分

考点:数组方法
思路:利用splice()方法

/**
 * @param {Object} oldArr
 * @param {Object} num
 * */
const splitArray = (oldArr, num) => {
   
  // TODO:请补充代码实现功能
  let arr = []
  while (oldArr.length > 0) {
   
    arr.push(oldArr.splice(0,num))
  }
  return arr
};
module.exports = splitArray; // 检测需要,请勿删除


【真题练习】新鲜的蔬菜

考点:flex布局
思路:照着写就行

/* TODO:待补充代码 */
.box{
   
  display: flex;
}
#box1{
   
  justify-content: center;
  align-items: center;
}
#box2{
   
  justify-content: space-between;
}
#box2 .item:last-child{
   
  align-self: flex-end;
}
#box3 {
   
   justify-content: space-between;  /* 不加这个不能pass,有点玄学*/
} 
#box3 .item:nth-child(2){
   
  align-self: center;
}
#box3 .item:nth-child(3){
   
  align-self: flex-end;
}

【真题练习】水果消消乐

考点: DOM操作
思路:1 先做需求:隐藏开始按钮,方格上的图片显示后又隐藏。 2 再做第一次点击图片翻转效果。 3 做第二次点击的逻辑判断,若水果相同则,进行消除,加分操作,水果不同,进行隐藏,减分操作。

// TODO:请补充代码
const startBtn = document.querySelector("#start")
const imgList = document.querySelectorAll(".img-box img")
const boxList = document.querySelectorAll(".img-box")
const scoreEle = document.querySelector("#score")

const changeDisplay = (element, status) => element.style.display = status
// 隐藏开始按钮,方格上的图片显示后又隐藏
function start(){
   
    changeDisplay(startBtn,"none")
    // imgList转成数组之后用forEach遍历
    Array.from(imgList).forEach(img=>{
   
        changeDisplay(img,"block")
    })
    setTimeout(function(){
   
        Array.from(imgList).forEach(img=>{
   
            changeDisplay(img,"none")
        })
    },1000)
}


// 正式开始游戏
let score = 0  // 记录分数
let num = 0  // 记录是第一次翻牌还是第二次翻牌
let preId = ""
let preText = ""
function game(){
   

}
function startGame() {
   
    start()
    // 给每个box绑定点击事件,不能给img元素绑定点击事件,因为img元素是display:none
    Array.from(boxList).forEach(box=>{
   
        box.addEventListener("click",function(e){
   
            num++
            if(num === 1){
   
                // 如果第一次点击
                preText = e.target.firstElementChild.alt 
                preId = e.target.id
                changeDisplay(e.target.firstElementChild,"block")
            }else{
   
                // 第二次点击
                let nowText = e.target.firstElementChild.alt 
                let nowId = e.target.id
                changeDisplay(e.target.firstElementChild,"block")
                console.log(nowText,preText,nowId,preId)
                if (nowText === preText){
   
                    //水果相同 进行消除,加分操作
                    score += 2
                    // 这里得用不可见,要不然位置顺序会变
                    // 不可见仍然触发点击事件
                    setTimeout(function(){
   
                        document.getElementById(preId).style.visibility = "hidden"
                        document.getElementById(nowId).style.visibility = "hidden"
                        scoreEle.innerText = score
                        // 清空
                        num = 0
                        preId = ""
                        preText = ""
                    },1000)
                } else {
   
                     //水果不相同 进行隐藏,减分操作
                     score -= 2
                     // 隐藏图像
                     setTimeout(function(){
   
                        document.getElementById(preId).firstElementChild.style.display = "none"
                        document.getElementById(nowId).firstElementChild
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值