var students = ["Brandon", "Daniel"];
var greetStudent = "Hello, ${students[1]}"
for (let i = 0; i < students.length; i++) {
greetStudent(students[i]);
}
for (let student of students) {
greetStudent(student);
}
How do I get it to show with console.log " Daniel" as it is ${students[1]}?
I'm a starter in javascript. Please help me, I would appreciate it!
greetStudent has to be a function, not a variable since you are calling it.
const greetStudent = (student) => {
console.log(`Hello, ${student}`)
}
Define greetStudent as a function and use a template literal instead of a regular string.
let students = ["Brandon", "Daniel"];
const greetStudent = student => `Hello, ${student}`;
for (let i = 0; i < students.length; i++){
console.log(greetStudent(students[i]));
}
for (let student of students){
console.log(greetStudent(student));
}