get help in general - we have more specialized help rooms here: https://gitter.im/FreeCodeCamp/home
function sumFibs(num) {
//Initialize variables
var fibs = [0,1];
var oddIndex = [0,1];
var tmp = 0;
var sum = 0;
var index = 0;
//Create Fibonacci Number and checks if odd. Saves oddIndex.
for(var i = 1; i <=num; i++){
tmp = fibs[i]+fibs[i-1];
if(tmp%2!==0){
oddIndex.push(i+1);
}
fibs.push(tmp);
}
//Sum odd Fibonacci Numbers
for(var j = 0; j<oddIndex.length; j++){
index = oddIndex[j];
sum += fibs[index];
}
return sum;
}
sumFibs(6);
function sumFibs(num) {
//Initialize variables
var fibs = [0,1];
var tmp = 0;
var sum = 1;
//Create Fibonacci Number and checks if odd.
for(var i = 1; i <=num; i++){
tmp = fibs[i]+fibs[i-1];
if(tmp%2!==0){
sum += tmp;
}
fibs.push(tmp);
}
return sum;
}
sumFibs(4);
function sumFibs(num) {
//Initialize variables
var fibs = [0,1];
var tmp = 0;
var sum = 1;
//Create Fibonacci Number and checks if odd.
for(var i = 1; i <=num; i++){
tmp = fibs[i]+fibs[i-1];
if(tmp%2!==0){
sum += tmp;
}
if(tmp >= num){
return sum
}
fibs.push(tmp);
}
}
Quick question here.
I have two statments that are intended to accomplish the same purpose.
I'm not getting why sample 1 returns a full string and sample 2 returns am error. (If I put a return in either of the if statements, it returns the first letter of the string.)
function swap(str) {
var list = "";
for(var i = 0; i < str.length; i++) {
if(str.charAt(i).match(/[A-Z]/g)) {
list += str[i].toLowerCase();
//list[i].toLowerCase();
}
if(str.charAt(i).match(/[a-z]/g)) {
list += str[i].toUpperCase();
}
}
return list;
}
swap("The");
function swap(str) {
var list = "";
for(var i = 0; i < str.length; i++) {
if(str[i].charCodeAt() >= 65 || str[i].charcodeAt() <= 90) {
list += String.fromCharCode(str[i].charCodeAt(0) + 32);
}
if(str[i].charCodeAt() >= 97 || str[i].charcodeAt() <= 122) {
list += String.fromCharCode(str[i].charCodeAt(0) - 32);
}
}
return list;
}
swap("The");
By the way
str.charCodeAt(i);
is going to be more efficient than
str[i].charCodeAt(0);