// Please write your code directly below the corresponding numbers. // #1 var fu
ID: 3883830 • Letter: #
Question
// Please write your code directly below the corresponding numbers. // #1 var fullName = 'Linus Torvalds';
var birthYear = 1969;
// #2 var myArray = [];
// #3 myArray.push(fullName, birthYear);
console.log(myArray);
// #4 var splitName = ((fullName.split)(" "));
console.log(splitName);
// #5 function sayHello() {}
console.log('Hello,' + fullName[0] + '!');
// #6 function calcAge(present)
{ return (present - birthYear);
}
console.log(calcAge(2017));
// #7 function sumOddNumbers()
{}
var sum = 0;
for (sum = 1; sum < 5000; sum = sum + 2)
console.log(sum);
I need help with these questions
.6.Write another function called calcAge. This function should take one parameter, a year, and it should return the implied age of Linus Torvalds. Call the function passing the current year as the parameter. 7. Starting with the basic function given below, write a function called sumOddNumbers that will print to the console and return the sum of all the odd numbers from 1 to 5000. Consider using a loop, and don't forget to call the function afterwards!
Explanation / Answer
var fullName = 'Linus Torvalds';
var birthYear = 1969;
var myArray = [];
myArray.push(fullName, birthYear);
console.log(myArray);
var splitName = ((fullName.split)(" "));
console.log(splitName);
function sayHello() {
console.log('Hello,' + fullName[0] + '!');
}
sayHello();
//calculate presentAge
function calcAge(present) {
return (present - birthYear);
}
console.log(calcAge(2017));
//calculte number of odd numbers between 1,5000
function sumOddNumbers() {
var s = 0;
for (sum = 1; sum < 5000; sum = sum + 2)
s++;
console.log(s);
return s;
}
sumOddNumbers();
/*
sample output
[ 'Linus Torvalds', 1969 ]
[ 'Linus', 'Torvalds' ]
Hello,L!
48
2500
*/
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.