Published
Edited
Feb 26, 2019
Insert cell
Insert cell
Insert cell
Insert cell
Math.random(0,3)

Insert cell
Insert cell
//ask for low number and high number
function random_builder(min = 0, max){
return Math.floor(Math.random()*(max-min+1)+min);
}
Insert cell
random_builder(1,50)
Insert cell
function tester(value, min, max){
if (value <= max && value>=min){
return true;
}
else{
return false;
}
}
Insert cell
tester(10,10,100)
Insert cell
Insert cell
function stringFormatter(arrayInput, numberInput){
return("The number "+numberInput+" bestseller today is: "+arrayInput[numberInput-1].replace(/\b\w/g, l => l.toUpperCase()))
}
Insert cell
//test string formatter
stringFormatter(['harry potter','the hunger games','Prey','Mockingjay part 1'],4)
Insert cell
//array required, number optional
function stringFormatterOptionalSecond(arrayInput, numberInput=1){
if(arguments.length==1 || arguments.length == 2){
return("The number "+numberInput+" bestseller today is: "+arrayInput[numberInput-1].replace(/\b\w/g, l => l.toUpperCase()))
}
else{
return("You must supply an array")
}
}
Insert cell
stringFormatterOptionalSecond(['lf','harry potter'])
Insert cell
//array optional, number required
function stringFormatterOptionalFirst(input1,input2){
//check if it only has the number input
if(arguments.length ==1 && input1 === parseInt(input1,10)){
return("There was no array input, but it looks like you want the number " + input1 + " bestseller")
}
else if(arguments.length ==2){
return("The number "+input2+" bestseller today is: "+input1[input2-1].replace(/\b\w/g, l => l.toUpperCase()))
}
}
Insert cell
stringFormatterOptionalFirst(2)
Insert cell
//both optional
function stringFormatterOptionalBoth(input1, input2){
if(arguments.length==0){
return("You didn't supply a list or a number, so I'm printing this message")
}
else if(arguments.length ==1 && input1 === parseInt(input1,10)){
return("There was no array input, but it looks like you want the number " + input1 + " bestseller")
}
else if(arguments.length ==1 && input1 != parseInt(input1,10)){
return("I only printed your list, now give me a bestseller number")
}
else if(arguments.length ==2 && input2 == input1.length){
return("The number "+input2+" bestseller today is: "+input1[input2-1].replace(/\b\w/g, l => l.toUpperCase()))
}
else {
return("There was no " + input2 + " number bestseller in your list")
}
}
Insert cell
stringFormatterOptionalBoth(['harry potter'],2)
Insert cell
Insert cell
function passwordValidate(word){
//define trackers
let num_digits = 0;
let num_upper = 0;
let specials = '!@#$%^&*()-_+='
let num_special = 0;
//keep track of how many of each character
for(let i=0; i<word.length;i++){
//examine each character at i position in word.length
let character = word.charAt(i)
//check if it's a number and count the numbers
if(!isNaN(character)){
num_digits++;
}
//check if it's an UpperCase and count the uppercase
if(isNaN(character) && character == character.toUpperCase() && specials.indexOf(character)==-1 ){
num_upper++;
}
//check if it's a special character and count the special character
if(specials.indexOf(character)>-1){
num_special++;
}
}
//check the password requirements
if(word.length>=8 && word.length<=14){
if(num_digits>=2){
if(num_upper>=1){
if(num_special>=1){
return ("success!")
} else {
return ("Needs 1 or more special characters")
}
} else {
return ("Needs 1 or more uppercase letters")
}
} else {
return ("Needs 2 or more digits")
}
} else {
return ("Needs to be between 8-14 characters. \nYour password is currently " + word.length + " characters long")
}
}
Insert cell
passwordValidate('Pizza444!')
Insert cell
Insert cell
function exponent(digit1, digit2){
let redefine = 1;
for(let i=0; i<digit2; i++){
redefine = redefine*digit1
}
return(redefine)
}
Insert cell
exponent(5,4)
Insert cell
Insert cell
function minMax(numbers){
let first_value = numbers[0]
let min = first_value
let max = first_value
//loop through the list
for(let i=0;i<numbers.length;i++){
//if the current value in the loop is bigger than min, set it to min
//if 2 is less than 3, make 2 the new minimum
if(numbers[i]<min){
min = numbers[i]
console.log("Min is now " + min)
}
if(numbers[i]>max){
max = numbers[i]
console.log("Max is now " + max)
}
}
return("Min is "+min+ " and Max is "+max)
}
Insert cell
num_list = [0,1,3,100,5]
Insert cell
minMax(num_list)
Insert cell
Insert cell
guess = 'b'
Insert cell
Insert cell
function guessHangman(){
console.log("Begin the game!")
//let guess = `${guess}`
console.log(`Your guess was ${guess}`)
let num_guesses = 0
let word = 'bumblebee'
let wordlength = word.length
let num_dashes = ''
let show_word = num_dashes

let num_tries = 8
if(word.length>15 || word.length<5){
console.log("Your word '" + word + "' is of length " + word.length + ", please try again with a word length of between 5 and 15 characters")
}
else {
//start loop to draw dashes
for(let i=0; i<wordlength;i++){
num_dashes = num_dashes.concat('-')
show_word = num_dashes
}
console.log('This is what the hidden word looks like: '+show_word)

//process clues
for(let i=0; i<wordlength;i++){
//if(word.includes(guess)===true){
//show where guess is inside word
//loop through each char and if char = guess, replace - with char
if(word.charAt(i)==guess){
console.log("the string at position " +i+ " is "+ show_word.charAt(i))
//show_word[i] = show_word[i].replace('-',guess)
show_word[i] = guess
console.log(show_word)
}
else {
console.log('not done yet')//num_tries--;
//console.log('you guessed incorrectly, you have ' + num_tries + " tries left")
//console.log("here's the word again: " +num_dashes)
}
}
}
}
//keep track of guesses
//if guess = 1, show the word with instances of correctly guessed letters filled in
//print number of tries left
//if guess >8 and puzzle not solved, game over, show completed word and Game Over
//if guess<=8 and puzzle solved, show completed word and congratulations

//hardcoded word (5-15 letters)

//guess letter through use input


Insert cell
guessHangman()
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more