Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                
              
            
!

CSS

              
                
              
            
!

JS

              
                /* You're staying in NYC for a month. There's so much to do and see but you're presented with 1 tough decision: buy a monthly MetroCard for $127 or a pay-per-ride MetroCard that costs $2.75 per swipe?

1. Write a function that takes in a number of rides and returns the savings you'd receive from buying a monthly card. If the savings are negative, that means you'd save more from buying a pay-per-ride card!

2. Write another function that takes in the savings returned from the previous function. This function should return a message that either suggests to buy a monthly MetroCard or a pay-per-ride. This message should also include how much you'd be saving if you buy this card.

Use printToScreen() to print the messages returned from function 2 for 30 rides, 45 rides, 60 rides, and a user-inputted custom number of rides!

Note: use toFixed(2) to round to the nearest 2 decimal points
*/

// Enter your code below this line
//1

const metrocard1 = (rides) => {
  let answer = rides*2.5;
  return answer-127;
}




//let savings = printToScreen(metrocard1(5))

//2

const metrocard2 = (savings) => {
  let rideNumber = savings;
  let answer = savings*2.75;
  answer = answer-127;
  var answer1 = answer.toFixed(2)
  if(answer1 == 0 || answer1 > 0){
    printToScreen("With " + rideNumber + " rides")
    printToScreen("You should purchase a monthly MetroCard! Your savings will be " + answer1)
  }
  if(answer1 < 0){
    let answer2 = Math.abs(answer1)
    var answer3 = answer2.toFixed(2)
    printToScreen("With " + rideNumber + " rides")
    printToScreen("You should purchase a pay-per-ride MetroCard! Your savings will be " + answer3)
  }
}
let userRides = prompt("How many rides?")

printToScreen(metrocard2(userRides))



//3


// DO NOT ALTER CODE WRITTEN BELOW THIS LINE
function printToScreen(text) {
  let r = Math.floor(Math.floor(Math.random() * 255 + 1));
  let g = Math.floor(Math.floor(Math.random() * 255 + 1));
  let b = Math.floor(Math.floor(Math.random() * 255 + 1));
  const svg = d3
    .select("body")
    .append("svg")
    .attr("width", 1500)
    .attr("height", 50);

  svg
    .append("text")
    .attr("y", 37.5)
    .attr("width", 450)
    .attr("height", 50)
    .attr("x", -1000)
    .attr("font-weight", "bold")
    .attr("font-size", "20px")
    .attr("fill", `rgb(${r},${g},${b}`)
    .attr("font-family", "Roboto")
    .text(text)
    .transition()
    .duration(1000)
    .attr("x", 37.5);
}

              
            
!
999px

Console