Skip to content

w01 d01 #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions challenges/bottles-of-beer-song.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,27 @@
*/

// YOUR CODE HERE

function writeSong(a) {
for (var i = a; i > 0; i--){
if (i===1){
console.log (i + " bottle of beer on the wall")
console.log (i + " bottle of beer!")
console.log ("Take one down and pass it around,")
}
else {
console.log (i + " bottles of beer on the wall,")
console.log (i + " bottles of beer!")
console.log ("Take one down and pass it around,")
}
if (i === 1){
console.log ("No more bottles of beer on the wall...")
} else if (i === 2){
console.log (i-1 + " bottle of beer on the wall...")
} else {
console.log (i-1 + " bottles of beer on the wall...")
}
console.log("")
}
}
writeSong(5);
51 changes: 51 additions & 0 deletions challenges/palindrome-detector.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,54 @@
*/

// YOUR CODE HERE
function isPalindrome (n){
palindromeForward = n.split('');
palindromeInitial = palindromeForward;
palindromeReverse = n.split('');
reverse = palindromeReverse.reverse();
for (var i = 0; i < palindromeInitial.length; i++ ) {
if (palindromeForward[i]=== " "){
palindromeForward.splice(i,1);
}
}
for (var i = 0; i < palindromeInitial.length; i++ ) {
if (palindromeForward[i]=== ","){
palindromeForward.splice(i,1);
}
}
for (var i = 0; i < palindromeInitial.length; i++ ) {
if (palindromeForward[i]=== "."){
palindromeForward.splice(i,1);
}
}
for (var i = 0; i < palindromeInitial.length; i++ ) {
if (palindromeForward[i]=== ":"){
palindromeForward.splice(i,1);
}
}
for (var i = 0; i < palindromeReverse.length; i++ ) {
if (palindromeReverse[i]=== " "){
palindromeReverse.splice(i,1);
}
}
for (var i = 0; i < palindromeReverse.length; i++ ) {
if (palindromeReverse[i]=== ","){
palindromeReverse.splice(i,1);
}
}
for (var i = 0; i < palindromeReverse.length; i++ ) {
if (palindromeReverse[i]=== "."){
palindromeReverse.splice(i,1);
}
}
for (var i = 0; i < palindromeReverse.length; i++ ) {
if (palindromeReverse[i]=== ":"){
palindromeReverse.splice(i,1);
}
}
stringForward = palindromeForward.join('');
stringBackward = palindromeReverse.join('');
forward = stringForward.toLowerCase();
backward = stringBackward.toLowerCase();
return (forward === backward)
}
18 changes: 18 additions & 0 deletions challenges/primes.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,21 @@
*/

// YOUR CODE HERE
function isPrime(num){
for(var i=2; i < num; i++){
if(num % i === 0) {
return false;
}
}
return num > 1;
}
function primes(max){
var primeArray = [];
for (var i=1; i <= max; i++){
isPrime(i);
if(isPrime(i)===true){
primeArray.push(i);
}
}
return primeArray;
}
6 changes: 6 additions & 0 deletions challenges/shakespearian-insult-generator.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.