我需要一段javascript实现生日祝福的代码
时间: 2023-02-28 13:52:14 浏览: 64
好的,这是一段生日祝福的 JavaScript 代码:
```
function birthdayGreeting(name) {
console.log("Happy Birthday, " + name + "!");
console.log("Wishing you all the best on your special day.");
}
birthdayGreeting("John");
```
这段代码使用了一个函数 `birthdayGreeting`,它接受一个参数 `name`,然后在控制台输出生日祝福语。
使用时只需调用 `birthdayGreeting` 函数,并传入一个参数(例如,这里的 "John")即可。
相关问题
帮我写一段JavaScript数组去重代码
var arr = [1, 2, 3, 4, 4, 5]
var newArr = arr.filter(function(item, index, self) {
return self.indexOf(item) == index;
})
帮我用JavaScript写一段ATM机代码
好的,以下是一段简单的ATM机代码,用JavaScript实现:
```
let balance = 1000; // 初始余额为1000元
function withdraw(amount) {
if (amount < 0) {
return "无效金额"; // 不能取负数金额
}
if (balance < amount) {
return "余额不足"; // 余额不足无法取款
}
balance -= amount; // 更新余额
return "取款成功,当前余额为:" + balance + "元";
}
function deposit(amount) {
if (amount < 0) {
return "无效金额"; // 不能存负数金额
}
balance += amount; // 更新余额
return "存款成功,当前余额为:" + balance + "元";
}
// 示例代码
console.log(withdraw(-100)); // "无效金额"
console.log(withdraw(2000)); // "余额不足"
console.log(withdraw(500)); // "取款成功,当前余额为:500元"
console.log(deposit(1000)); // "存款成功,当前余额为:1500元"
```
希望这段代码能够满足您的需求。