列表

详情


JS12. 模板字符串

描述

请补全JavaScript代码,实现以下功能:
1. 根据已有的person对象的注册时间求出距离当前时间的天数(天数向下取整)。
2. 将获得的天数和person数据拼接成字符串,作为h2标签的内容。
注意:使用模板字符串进行字符串拼接,字符串最终内容如:尊贵的牛客网2级用户小丽您好,您已经注册牛客网3天啦~

原站题解

HTML/CSS/JavaScript 解法, 执行用时: 1695ms, 内存消耗: 77808KB, 提交时间: 2022-02-08

{"css":"","js":"","html":"<!DOCTYPE html>\n<html lang=\"en\">\n    <head>\n        <meta charset=\"UTF-8\">\n    </head>\n    <body>\n        <h2></h2>\n\n        <script>\n            var person = {\n                level: '2',\n                name: '小丽',\n                registTime: '2021-11-01',\n            }\n            var h2 = document.querySelector('h2');\n            // 补全代码\n                        var rDate = new Date(person.registTime).getTime();\n            var rTime = Math.floor((new Date().getTime()-rDate)/(1000*60*60*24))\n            h2.innerText=`尊贵的牛客网${person.level}级用户${person.name}您好,您已经注册牛客网${rTime}天啦~`\n        </script>\n    </body>\n</html>","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 1741ms, 内存消耗: 77772KB, 提交时间: 2021-12-19

{"css":"","js":"","html":"<!DOCTYPE html>\n<html lang=\"en\">\n    <head>\n        <meta charset=\"UTF-8\">\n    </head>\n    <body>\n        <h2></h2>\n\n        <script>\n            var person = {\n                level: '2',\n                name: '小丽',\n                registTime: '2021-11-01',\n            }\n            var h2 = document.querySelector('h2');\n            // 补全代码\n            let date = new Date();\n            let now = date.getTime()\n            let start = new Date(person.registTime).getTime()\n            let step = now - start;\n            let days = Math.floor(step/(24 * 60 * 60 * 1000))\n            h2.innerText = `尊敬的牛客网${person.level}级用户${person.name}您好,你已经注册牛客网${days}天啦~`\n        </script>\n    </body>\n</html>","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 1742ms, 内存消耗: 77868KB, 提交时间: 2022-01-25

{"css":"","js":"","html":"<!DOCTYPE html>\n<html lang=\"en\">\n    <head>\n        <meta charset=\"UTF-8\">\n    </head>\n    <body>\n        <h2></h2>\n\n        <script>\n            var person = {\n                level: '2',\n                name: '小丽',\n                registTime: '2021-11-01',\n            }\n            var h2 = document.querySelector('h2');\n            // 补全代码\n            var str;\n            var today = new Date();\n            var registerDay = new Date(person.registTime);\n            var days = (today - registerDay)/(1000 * 60 * 60 * 24);\n            days = Math.floor(days);\n            str = `尊贵的牛客网${person.level}级用户${person.name}您好,您已经注册牛客网${days}天啦~`;\n            h2.innerHTML = str\n            \n        </script>\n    </body>\n</html>","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 1746ms, 内存消耗: 77772KB, 提交时间: 2022-01-27

{"css":"","js":"","html":"<!DOCTYPE html>\n<html lang=\"en\">\n    <head>\n        <meta charset=\"UTF-8\">\n    </head>\n    <body>\n        <h2></h2>\n\n        <script>\n            var person = {\n                level: '2',\n                name: '小丽',\n                registTime: '2021-11-01',\n            }\n            var h2 = document.querySelector('h2');\n            // 补全代码\n            let nowDate = new Date();\n        let registTime = new Date(person.registTime);\n        let time = Math.floor((nowDate - registTime) / (1000 * 60 * 60 * 24));\n        h2.innerHTML = `\n            尊贵的牛客网${person.level}级用户${person.name}您好,您已经注册牛客网${time}天啦~\n        `;\n        </script>\n    </body>\n</html>","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 1747ms, 内存消耗: 77772KB, 提交时间: 2021-12-05

{"css":"","js":"","html":"<!DOCTYPE html>\n<html lang=\"en\">\n    <head>\n        <meta charset=\"UTF-8\">\n    </head>\n    <body>\n        <h2></h2>\n\n        <script>\n            var person = {\n                level: '2',\n                name: '小丽',\n                registTime: '2021-11-01',\n            }\n            var h2 = document.querySelector('h2');\n            // 补全代码\n            const _getDuration = registTime => {\n    var start = new Date(registTime)\n    var end = new Date()\n    var dates = Math.floor((end - start) / (1000 * 60 * 60 * 24))\n    return dates\n}\nh2.innerText = `尊贵的牛客网${person.level}级用户${person.name}您好,您已经注册牛客网${_getDuration(person.registTime) }天啦~`\n\n        </script>\n    </body>\n</html>","libs":[]}

上一题