Advertisement
pacho_the_python

Untitled

Mar 9th, 2023
560
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function towns(townData) {
  2.     class Town {
  3.         constructor(name, latitude, longitude) {
  4.             this.name = name
  5.             this.latitude = latitude
  6.             this.longitude = longitude
  7.         }
  8.         getInfo() {
  9.             console.log(`{ town: '${this.name}', latitude: '${this.latitude}', longitude: '${this.longitude}' }`)
  10.         }
  11.     }
  12.     for (let i = 0; i < townData.length; i++) {
  13.         let currentData =  townData[i].split(' | ')
  14.         let townName = currentData[0]
  15.         let currentLatitude = Number(currentData[1]).toFixed(2)
  16.         let currentLongitude = Number(currentData[2]).toFixed(2)
  17.         let newTown = new Town(townName, currentLatitude, currentLongitude)
  18.         newTown.getInfo()
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement