方法一:使用嵌套循环
```javascript
function printInvertedTriangle(n) {
for (let i = n; i >= 1; i--) {
// 打印空格
for (let j = 0; j < n - i; j++) {
console.log(" ");
}
// 打印星号
for (let k = 0; k < 2 * i - 1; k++) {
console.log("*");
}
}
}
// 调用函数
printInvertedTriangle(5);
```
方法二:使用readline-sync模块
```javascript
const readline = require("readline-sync");
function printInvertedTriangle(num) {
for (let i = num; i >= 1; i--) {
let c = "";
let d = "";
for (let j = 0; j < num - i; j++) {
c += " ";
}
for (let k = 0; k < 2 * i - 1; k++) {
d += "*";
}
console.log(c + d);
}
}
// 获取用户输入
const num = parseInt(readline.question("请输入一个数字: "));
printInvertedTriangle(num);
```
方法三:使用HTML和JavaScript
```html