admin管理员组文章数量:1386649
Hello so my question is about this assignment and how I am stuck on how to proceed with getting the persons name to be added to the greeting. The assignment directions are as follows: Create a function called greet that has one parameter called name and does not return a value. When greet is called, it should say hello to the value passed in as the argument to name. For instance, greet("Bob"); should print out Hello, Bob!
Create a function to greet a person and return their name.
var greet_name = function(person_name, greet) {
var text = greet + ',' + name;
var person_name = text
text = "Enter your name here";
person_name = prompt(text); stop
console.log(text);
var greet = greet_name(person_name, greet);
};
greet_name()
Some advice on what the next steps would be great or just suggestions on places to edit the code.
Thanks
Hello so my question is about this assignment and how I am stuck on how to proceed with getting the persons name to be added to the greeting. The assignment directions are as follows: Create a function called greet that has one parameter called name and does not return a value. When greet is called, it should say hello to the value passed in as the argument to name. For instance, greet("Bob"); should print out Hello, Bob!
Create a function to greet a person and return their name.
var greet_name = function(person_name, greet) {
var text = greet + ',' + name;
var person_name = text
text = "Enter your name here";
person_name = prompt(text); stop
console.log(text);
var greet = greet_name(person_name, greet);
};
greet_name()
Some advice on what the next steps would be great or just suggestions on places to edit the code.
Thanks
Share Improve this question asked Feb 17, 2018 at 2:34 Cody BoltonCody Bolton 211 gold badge2 silver badges2 bronze badges 1- 2 Did you encounter some problem? "Some advice would be great" isn't a valid question. – Lightness Races in Orbit Commented Feb 17, 2018 at 2:47
6 Answers
Reset to default 3
function greet(name) {
console.log("Hello, " + name + "!");
}
greet("Bob");
Okay, so we only need one parameter for the function:
function greet(name){
And We know that we don't need to have the function return anything, but it needs to print out the name: console.log("Hello, " + name);
Additionally, we want a prompt so the user can enter a name of their choice. We can actually do this during the function call: greet(prompt("Enter Name:"))
Thus, we have a fully functional greeter. Final product:
function greet(name){
console.log("Hello, "+ name);
}
greet(prompt("Enter Name:"));
Try This
var greet_name = function(person_name, greet) {
console.log(greet + " " + person_name);
};
greet_name(prompt("Enter Your Name : ","Enter Name"),"Wele");
This Might be an easier and cleaner way to do it.
var greeting = (userName)=>{
var userName = prompt("Enter Name");
alert("Hello " + userName + "!" );
}
greeting();
This is my solution to your problem:
var greet_name = function () {
let person_name = prompt('Enter your name here: ');
console.log(`Hello ${person_name}`);
};
greet_name('Mike');
Use `` instead of "".
function greet(person_name) {
return Hello, ${person_name} how are you doing today?
;
}
本文标签: How to use a function to greet a person in JavaScriptStack Overflow
版权声明:本文标题:How to use a function to greet a person in JavaScript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744520174a2610408.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论