列表

详情


JS1. 直角三角形

描述

请补全JavaScript代码,要求在页面上渲染出一个直角三角形,三角形换行要求使用"br"实现。三角形如下:
*
**
***

原站题解

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

{"css":"","js":"","html":"<!DOCTYPE html>\n<html lang=\"en\">\n    <head>\n        <meta charset=\"UTF-8\">\n    </head>\n    <body>\n        <div class='triangle'></div>\n\n        <script>\n            var triangle = document.querySelector('.triangle');\n          var str = '';\n    for (let i = 0; i < 3; i++){\n        for (let j = 0; j <= i; j++){\n            str += '*';\n        }\n        str += '<br>';\n    }\n    triangle.innerHTML = str;\n        </script>\n    </body>\n</html>","libs":[]}

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

{"css":"","js":"","html":"<!DOCTYPE html>\n<html lang=\"en\">\n    <head>\n        <meta charset=\"UTF-8\">\n    </head>\n    <body>\n        <div class='triangle'></div>\n\n        <script>\n            var triangle = document.querySelector('.triangle');\n            // 补全代码\n            triangle.innerHTML = `*<br>**<br>***<br>`\n        </script>\n    </body>\n</html>","libs":[]}

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

{"css":"","js":"","html":"<!DOCTYPE html>\n<html lang=\"en\">\n    <head>\n        <meta charset=\"UTF-8\">\n    </head>\n    <body>\n        <div class='triangle'></div>\n\n        <script>\n            var triangle = document.querySelector('.triangle');\n            // 补全代码\n            var str = \"\"\n            for(let i = 1; i <= 3; i++) {\n                // 外层循环控制行\n                for(let j = 1; j <= i; j++) {\n                    // 内层循环控制内容\n                    str += \"*\"\n                }\n                str += \"<br/>\"\n            }\n            triangle.innerHTML= str\n            \n        </script>\n    </body>\n</html>","libs":[]}

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

{"css":"","js":"","html":"<!DOCTYPE html>\n<html lang=\"en\">\n    <head>\n        <meta charset=\"UTF-8\">\n    </head>\n    <body>\n        <div class='triangle'></div>\n\n        <script>\n            var triangle = document.querySelector('.triangle');\n            // 补全代码\n          var str = \"\"\n          \n          for(var i = 0; i < 4; i++){\n             str += '*'.repeat(i) + '<br/>' \n          }\n            triangle.innerHTML = str\n        </script>\n    </body>\n</html>","libs":[]}

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

{"css":"","js":"","html":"<!DOCTYPE html>\n<html lang=\"en\">\n    <head>\n        <meta charset=\"UTF-8\">\n    </head>\n    <body>\n        <div class='triangle'></div>\n\n        <script>\n            var triangle = document.querySelector('.triangle');\n            // 补全代码\n            str=\"*\"+\"<br>\"+\"**\"+\"<br>\"+\"***\"+\"<br>\";\n            triangle.innerHTML=str;\n        </script>\n    </body>\n</html>","libs":[]}

上一题

下一题