Skip to content

Instantly share code, notes, and snippets.

@jennli
Last active January 21, 2016 02:22
Show Gist options
  • Save jennli/bcf47a46fe6719bd707f to your computer and use it in GitHub Desktop.
Save jennli/bcf47a46fe6719bd707f to your computer and use it in GitHub Desktop.
function fizzbuzz(fizz, buzz)
{
if (typeof(fizz) !== "number" || typeof(buzz) !== "number"){
console.error("one of your parameter is not a number!");
return ;
}
for (var i = 1 ; i <=100; i++ ){
if (i % fizz === 0 && i % buzz === 0){
console.log("fizzbuzz");
}
else if (i% fizz === 0 )
{
console.log("fizz");
}
else if (i % buzz === 0){
console.log("buzz");
}
else
{
console.log(i);
}
}
return;
}
//grade
var keepLooping = true;
while (keepLooping){
var grade = prompt("please enter your grade: ");
if (grade > 100){
alert("your grade is greater than 100! try again!");
}
else if(grade < 0){
alert("your grade can't be a negative value!! Try again!" );
}
else
{
keepLooping = false;
}
}
switch(true){
// case grade < 0:
// console.log("your grade can't be a negative value!!");
// break;
// case grade > 100:
// console.log("how did you get a grade greater than 100??");
// break;
case (grade >= 90 && grade <= 100):
console.log("You got an A!");
break;
case (grade >= 80 && grade < 90):
console.log("You got a B!");
break;
case (grade >= 70 && grade < 80):
console.log("You got a C!");
break;
case (grade >= 60 && grade < 70):
console.log("You got a D!");
break;
default:
console.log("You failed..");
break;
}
function capitalize(string){
if (typeof(string) !== "string"){
return null;
}
else{
return string[0].toUpperCase() + string.substr(1, string.length);
}
}
function capitalizeEven(string){
if (typeof(string) !== "string"){
return null;
}
else{
var stringArray = string.split("");
for (var i = 0; i < stringArray.length; i ++){
if (i%2 !== 0 ){
stringArray[i] = string[i].toUpperCase();
}
else{
stringArray[i] = string[i];
}
}
return stringArray.join("");
}
}
function findOccurence(){
for(var y = 2014; y <= 2050; y++){
var date = new Date(y, 0, 1);
if(date.getDay() === 0){
return date;
}
}
}
function guessNumber(){
var randy = Math.floor((Math.random() * 100) + 1)
var correct = false;
var trials = 0;
alert("A random number between 1 and 100 has been drawn!");
while(!correct){
trials +=1;
input = parseInt(prompt("please enter your guess!"));
if (typeof(input) != "number"){
alert("that's not a number");
}
else if(input === randy){
alert("good work! you guessed in "+ trials+ " tries!");
correct = true;
}
else if(input > randy){
alert("Your number is too high, try again!");
}
else {
alert("your number is too low, try again");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment