rafase282 / my-freecodecamp-code Goto Github PK
View Code? Open in Web Editor NEWMy code from the bootcamp.
Home Page: http://rafase282.github.io/My-FreeCodeCamp-Code
My code from the bootcamp.
Home Page: http://rafase282.github.io/My-FreeCodeCamp-Code
At Target the same element with multiple jQuery Selectors, it said : Only add one class with each of your three selectors.
@Rafase282 . The first,thank you very much for your good tutorial, but in this wiki page ( https://github.com/Rafase282/My-FreeCodeCamp-Code/wiki/Bonfire-Truncate-a-string) I have another idea.
eg:
function truncate(str, num) {
var truncd = '';
if (str.length > num) {
truncd = str.slice(0,num-3) + '...';
return truncd;
}
return str;
}
truncate("A-tisket a-tasket A green and yellow basket", 11);
I has runed in chrome console:
> truncate("A-tisket a-tasket A green and yellow basket", 11);
< "A-tisket..."
> truncate("A-tisket a-tasket A green and yellow basket", 1);
< "A-tisket a-tasket A green and yellow bask..."
> truncate("A-tisket a-tasket A green and yellow basket", 2);
< "A-tisket a-tasket A green and yellow baske..."
> truncate("A-tisket a-tasket A green and yellow basket", 3);
< "..."
> truncate("A-tisket a-tasket A green and yellow basket", "A-tisket a-tasket A green and yellow basket".length);
< "A-tisket a-tasket A green and yellow basket"
if num <=3
, the truncate()
is not the best. I will change the function, like this:
function truncate(str, num) {
var truncd = "";
if (str.length > num && num > 3) {
truncd = str.slice(0, num -3) + "...";
} else if (str.length > num && num <= 3) {
truncd = str.slice(0, num) + "...";
} else {
truncd = str.slice(0, num);
}
return truncd;
}
truncate("A-tisket a-tasket A green and yellow basket", 11);
Chrome console result:
> truncate("A-tisket a-tasket A green and yellow basket", 11);
< "A-tisket..."
> truncate("A-tisket a-tasket A green and yellow basket", 1);
< "A..."
> truncate("A-tisket a-tasket A green and yellow basket", 2);
< "A-..."
> truncate("A-tisket a-tasket A green and yellow basket", 3);
< "A-t..."
> truncate("A-tisket a-tasket A green and yellow basket", "A-tisket a-tasket A green and yellow basket".length);
< "A-tisket a-tasket A green and yellow basket"
If you have any better solutions, welcome to share
Hi!
The code you proposed doesn't work that well ;) My final version below:
`function checkCashRegister(price, cash, cid) {
var totalChange = +(cash - price).toFixed(2);
var stdCurr = [0.01, 0.05, 0.10, 0.25, 1, 5, 10, 20, 100];
var currType;
var stdCurrAmount;
var currCurrency;
var changeArr = [];
var totalCash = +cid.map(function(money) {
return money[1];
}).reduce(function(cash1, cash2) {
return cash1 + cash2;
}).toFixed(2);
var resultAmount = 0;
function check(result) {
for (var i = 0; i < result.length; i++){
resultAmount += result[i][1];
}
if (resultAmount < totalChange) {
return false;
} else {
return true;
}
}
if (totalChange > totalCash) {
return 'Insufficient Funds';
} else if (totalChange === totalCash) {
return 'Closed';
}
for (var i = +cid.length - 1; i >= 0; i--) {
currCurrency = +cid[i][1].toFixed(2);
currType = cid[i][0];
if (+stdCurr[i].toFixed(2) <= +totalChange.toFixed(2)) {
stdCurrAmount = Math.floor(currCurrency / stdCurr[i]);
if ((stdCurr[i] * stdCurrAmount) >= totalChange) {
stdCurrAmount = Math.floor(totalChange / stdCurr[i]);
}
currCurrency = +(stdCurr[i] * stdCurrAmount).toFixed(2);
totalChange = +(totalChange - currCurrency).toFixed(2);
cid[i][1] = currCurrency;
changeArr.push([currType, currCurrency]);
}
}
if (check(changeArr) === false){
return 'Insufficient Funds';
} else {
return changeArr;
}
}`
Just a general question - What is the program you used to produce the hand-drawn looking images? Thanks
telephoneCheck("1 555)555-5555")
telephoneCheck("555)-555-5555")
telephoneCheck("(555-555-5555")
strings above should return "false",but it isn't.
function truncate(str, num) {
var truncd = '';
if (str.length > num) {
truncd = str.slice(0,num-3) + '...';
return truncd;
}
return str;
}
does not accommodate
truncateString("A-", 1) should return "A...".
truncateString("Absolutely Longer", 2) should return "Ab...".
Fix------
function truncateString(str, num) {
var truncString = '';
if (num < 3) {
truncString = str.slice(0, num) + '...';
return truncString;
}
else if(str.length > num) {
truncString = str.slice(0, num - 3) + '...';
return truncString;
}
return str;
}
The code you have adds three classes to #target1 when you're only supposed to only add one class with each of your three selectors. The last selector should add the class "btn-primary" to target one.
<script> $(document).ready(function() { $("button").addClass("animated"); $(".btn").addClass("shake"); $("#target1").addClass("btn-primary"); }); </script>can anybody tell me how to : Give the text input in your form the class form-control.
<style> h2 { font-family: Lobster, Monospace; }.thick-green-border {
border-color: green;
border-width: 10px;
border-style: solid;
border-radius: 50%;
}
"Get a hint" on freecodecamp is down (error 500 - internal server error), so I found this github page.
Unfortunately the solution given does not work / is not accepted by fcc, but this does
function lookUpProfile(firstName, prop){
// Only change code below this line
for (var i=0; i < contacts.length; i++) {
if (contacts[i].firstName === firstName) {
if (contacts[i].hasOwnProperty(prop)) {
return contacts[i][prop];
}
else {
return "No such property";
}
}
}
return "No such contact";
// Only change code above this line
}
I think .some()
is not known to beginners at that point.
checkCashRegister(19.50, 20.00, [["PENNY", 0.01], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 1.00], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]]) should return "Insufficient Funds".
This one is returning an incorrect array and not insufficient Funds
if (collection[c].hasOwnProperty(pre) || collection[c][pre] == pre) {
counter++;
}
Hi I'm trying your code in my code camp
This condition give wrong result you can change with && and don't compare collection[c][pre] with pre but just collection[c][pre] so that become's correct
Thx for attention
Hi there, I was going through the questions on FCC and I realized that more restrictions has been put on the Challenge Record Collection than the one you have on wiki.
Since there is no current way I know to contribute to the wiki on Github, I will just post my working solution down below so you can update it on yours.
// Setup
var collection = {
"2548": {
"album": "Slippery When Wet",
"artist": "Bon Jovi",
"tracks": [
"Let It Rock",
"You Give Love a Bad Name"
]
},
"2468": {
"album": "1999",
"artist": "Prince",
"tracks": [
"1999",
"Little Red Corvette"
]
},
"1245": {
"artist": "Robert Palmer",
"tracks": [ ]
},
"5439": {
"album": "ABBA Gold"
}
};
// Keep a copy of the collection for tests
var collectionCopy = JSON.parse(JSON.stringify(collection));
// Only change code below this line
function updateRecords(id, prop, value) {
if (value === "") {
delete collection[id][prop];
}
else if (prop !== "tracks") {
collection[id][prop] = value;
}
else if (!collection[id].hasOwnProperty("tracks")) {
collection[id][prop] = [];
collection[id][prop].push(value);
}
else {
collection[id][prop].push(value);
}
return collection;
}
// Alter values below to test your code
updateRecords(5439, "artist", "ABBA");
Broken Link found in the Wiki: https://github.com/Rafase282/My-FreeCodeCamp-Code/wiki/URL-Shortener-Microservice
... revisit http://freecodecamp.com/challenges/get-set-for-basejumps.
I believe the link has been changed to: https://www.freecodecamp.org/challenges/get-set-for-our-api-development-projects
I'm working on this project now and since it is suggested to use the third party api in lieu of registering for a twitch.tv api key, I don't think one of the user stories works now. The json response for one of the suggested closed account users (comster404) is as follows:
{"stream":null,"_links":{"self":"https://api.twitch.tv/kraken/streams/comster404","channel":"https://api.twitch.tv/kraken/channels/comster404"}}
this is the same response as an active offline account, so I don't see a way to distinguish between the two.
This condition getting failed on execution:
Cards Sequence 2, J, 9, 2, 7 should return "1 Bet"
They updated the requirements and you need to add a new "imaginary" integer, that follows after M(1000), because of the code snippet
decimalValue[index + 1] > numeral
(line 15)
I got the source code, that worked for me. I called the imaginary unit Y for 10000
function convertToRoman(num) {
// Create arrays with default conversion with matching indices.
var decimalValue = [1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000, 10000];
var romanValue = ['I', 'IV', 'V', 'IX', 'X', 'XL', 'L', 'XC', 'C', 'CD', 'D', 'CM', 'M', 'Y'];
// Create a copy of num to work on and an empty string variable for the final roman number
var numeral = num;
var roman = '';
// While the decimal number is greater than 0,
while (numeral > 0 && numeral < 4000) {
// Loop through the indices of the decimalValue array.
for (var index = 0; index <= decimalValue.length; index++) {
// Get the maximum decimal number less or equal then the decimal number.
if (decimalValue[index] <= numeral && decimalValue[index + 1] > numeral) {
// Add the Roman numeral & decrease numCopy by the decimal equivalent.
roman += romanValue[index];
numeral -= decimalValue[index];
}
}
}
return roman;
}
convertToRoman(12);
Hey there, you should change the code in order to cover this requirement: if prop is "tracks" but the album doesn't have a "tracks" property, create an empty array before adding the new value to the album's corresponding property.
Something like the following should work:
function updateRecords(id, prop, value) {
if (value === '') {
delete collection[id][prop];
} else if (prop !== 'tracks') {
collection[id][prop] = value;
} else {
!collection[id].hasOwnProperty('tracks') ? collection[id][prop] = []
: collection[id][prop];
collection[id][prop].push(value);
}
return collection;
}
On the page Lesson Review Record Collection the spoiler code and the hints does not create the empty array needed before adding the new value to the nested object properties. Adding in collection[id].tracks=[]
in the else if (prop!=='tracks')
fixes this.
So the function should look like such:
function updateRecords(id, prop, value) {
if (value===''){
delete collection[id][prop];
} else if (prop !== 'tracks') {
collection[id].tracks=[];
collection[id][prop] = value;
} else {
collection[id][prop].push(value);
}
return collection;
}
function booWho(bool) {
// the fastet way to solve this problem
return typeof bool==="boolean";
}
booWho(null);
/* another way to solve it
function booWho(bool) {
if (bool===true || bool===false){
return true;
}
else{
return false;
}
return bool;
}
booWho(false);
*/
Your code for it is not passing,
Should handle words without vowels.
translatePigLatin("rhythm") should return "rhythmay".
Thank you for this repo.
EDIT; I see it's already been updated in guide.
In the above code, you should be targeting one element by adding one class at a time.
Correction should be $("#target1").addClass("btn-primary")
Thanks for the great work bro!!
The app link in the voting app Wiki is broken. I see it is linked to a Cloud9 workspace. They usually go down after a while. Heroku is probably a better option.
Hi there,
I was just going through your code and I noticed that your solution leaves a trail to an infinite loop and in order to avoid that you need to add an extra element in your array N for 10000.
There are cases where there is enough change in the drawer, but not enough useful change. For example, if there's 1 $100 in the drawer, and you need $0.37 in change, you couldn't really make the change. Seems like it would be better to find the sum of useful change in drawer, rather than all change in drawer....
`<script>
$(document).ready(function() {
$("button").addclass("animated bounce");
});
</script>
`
it's not working.
I think you're probably wrong on this challenge. According to your original code, it's not possible to change fullName
when using function setFirstName
or setLastName
. Here is my fix to make it work.
var Person = function(firstAndLast) {
var arr = firstAndLast.split(' ');
this.getFirstName = function() {
return arr[0];
};
this.getLastName = function() {
return arr[1];
};
this.getFullName = function() {
return arr.join(' ');
};
this.setFirstName = function(first) {
arr[0] = first;
};
this.setLastName = function(last) {
arr[1] = last;
};
this.setFullName = function(firstAndLast) {
arr = firstAndLast.split(' ');
};
};
var bob = new Person('Bob Ross');
bob.getFullName();
This challenge was a lot of fun! I'm not sure whether someone had already pointed this issue out (I couldn't find someone else posting about it anywhere), but the button in the example program that stores the last answer to be used later (the "ANS" button) doesn't do anything; For example when you type "2+2=", 4 appears, then when you type "Ans+2=" you simply get 2, meaning it starts from 0 again, and nothing seems to be stored for later use.
I'm not sure if this would be considered a bug or not but I thought it was odd to have a button that doesn't do anything.
Here is the link to my code if it's any help: https://codepen.io/LeFonze/pen/pbzYGo
Custom background does not change base on weather conditions.
Code below is flawed: (calling an array of images on the jQuery function will not be successful)
getWeather = function(data) {
// other code in between.
// Array of backgroudn images.
var imgs = ['url("http://i.imgur.com/eI5KLUW.jpg")',
'url("http://i.imgur.com/rG0P1ro.jpg")', 'url("http://i.imgur.com/voCuONs.jpg")',
'url("http://i.imgur.com/5tFHSKa.jpg")',
];
// Select custom backgroudn image according to temperature range.
if (temp >= temps[0]) {
$('body').css('background-image', imgs[0]);
} else if (temp < temps[0] && temp >= temps[1]) {
$('body').css('background-image', imgs[1]);
} else if (temp < temps[1] && temp >= temps[2]) {
$('body').css('background-image', imgs[2]);
} else if (temp < temps[2]) {
$('body').css('background-image', imgs[3]);
}
};
Correct version: (sample)
$("body").css("background-image", "url(https://github.com/chrisjim316/freeCodeCamp-/blob/master/09-Intermediate-FE-Projects/Local%20Weather%20App/Images/backgroundChanging/thunderstorm.jpg?raw=true)");
Firstly, thank you for putting your code up for others to enjoy and benefit from. I solved the following bonfire but wondered if my code could be cleaner, so I looked around.
I saw your code. While I am sure it used to work, it now does not. I also specify the criteria it now does not qualify.
Bonfire: https://www.freecodecamp.org/challenges/truncate-a-string
Your code: https://github.com/Rafase282/My-FreeCodeCamp-Code/wiki/Bonfire-Truncate-a-string
How I solved it: https://pastebin.com/vdBbAurN
The part you didn't qualify: If the string (str) is less than or equal to 3 then do not count '...' towards the truncate total.
Have not yet see it
Hello Rafael,
i tried your code for the Make a person
bonfire but it has not worked. I modified it to the following and it worked again. Please give me feedback.
var Person = function(firstAndLast) {
var arr = firstAndLast.split(' ');
this.getFirstName = function() {
return arr[0];
};
this.getLastName = function() {
return arr[1];
};
this.getFullName = function() {
return arr[0] + " " + arr[1];
};
this.setFirstName = function(first) {
arr[0] = first;
};
this.setLastName = function(last) {
arr[1] = last;
};
this.setFullName = function(firstAndLast) {
arr = firstAndLast.split(' ');
};
};
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.