-3

I am building a weather forecast site using JavaScript's framework p5.js. I have a description about what's the weather like (ex. few clouds) but the problem is that the api I'm using has only lowercase description. I wan't them to be uppercase but i don't know how to capitalize them. Can somebody help me? (I tried many vanilla JavaScript methods)

var weather;

var apiPath = 'http://api.openweathermap.org/data/2.5/weather?q=';
var apiKey = '&appid=e0342ddf94a760131ffacfa0e12bddf4';
var unit = '&units=metric';

var input;

function setup() {
noCanvas(270,125);

var button = select('#submit');
button.mousePressed(weatherAskAndDraw);

input = select('#city');
}


function CapFirst(string) 
{
return string.charAt(0).toUpperCase() + string.slice(1);
}

function keyDraw(){
if (weather){
    var temp = weather.main.temp;
    var humidity = weather.main.humidity;
    var minTemp = weather.main.temp_min;
    var maxTemp = weather.main.temp_max;
    var country = weather.sys.country;
    var city = weather.name;
    var vis = weather.visibility;
    var des = weather.weather[0].description;
    var windSpeed = weather.wind.speed;

    fill(255);

    CapFirst(des);

    document.getElementById("p1").innerHTML = "City: " + city;
    document.getElementById("p2").innerHTML = "Description: " + des;
    document.getElementById("p3").innerHTML = "Temperature: " + temp;
    document.getElementById("p4").innerHTML = "Humidity: " + humidity;
    document.getElementById("p5").innerHTML = "Wind Speed: " + windSpeed;
}
}

function weatherAskAndDraw(){
var url = apiPath + input.value() + apiKey + unit;
loadJSON(url, gotData);

keyDraw();
}

function gotData(data){
weather = data;
}
Daisho Arch
  • 520
  • 2
  • 16

1 Answers1

1

I have not worked with P5.js but as simple js

    mode = "few clouds";
    string = mode.charAt(0).toUpperCase() + mode.substr(1,mode.length).toLowerCase();
    console.log(string);
Nisarg
  • 1,631
  • 6
  • 19
  • 31