DecodeMTL Application

node v0.12.18
version: 1.0.0
endpointsharetweet
Write a function called firstLetter that takes one string argument and returns the first letter of the string.
function firstletter (string) { return string.charAt(0); } firstletter("water")
Write a function called lastLetter that takes one string argument and returns the last letter of the string.
function lastletter (string) { return string.substr(string.length - 1); } lastletter("Mira is exhausted from moving")
Write a function called crazySum that takes an array of numbers, and returns the sum of each number multiplied by its position in the array. For example, if you pass [4, 8, 15, 16], the program will calculate 4*1 + 8*2 + 15*3 + 16*4 and give you that back as an answer.
function crazySum () { //code }
Write a function called fizzBuzz that doesn't take any arguments and doesn't return anything. This function should print all the numbers from 1 to 100. If the number is dividable by 3, then it should print FIZZ instead of the number. If the number is dividable by 5, then it should print BUZZ instead of the number. If the number is dividable by 3 AND 5, then it should print FIZZBUZZ instead of the number.
for (var i = 1; i <= 100; i++) { var isDividibleByThree = i % 3 === 0; var isDivisibleByFive = i % 5 === 0; if (isDividibleByThree && isDivisibleByFive) { console.log('FizzBuzz'); } else if (isDividibleByThree) { console.log('Fizz'); } else if (isDivisibleByFive) { console.log('Buzz'); } else { console.log(i); } };
Write a function called factorial that takes a number as argument and returns the factorial of that number.
function factorial(number) { return (number <= 1) ? 1 : factorial(number - 1) * number; } factorial(34)
Loading…

no comments

    sign in to comment