//
//  ViewController.swift
//  ChemicalFormula
//
//  Created by Neo Wang on 10/23/19.
//  Copyright © 2019 Neo Wang. All rights reserved.
//

import UIKit

class ViewController: UIViewController {
    var chemicals = [String:String]()

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        
        chemicals["H2O"] = "DiHydrogen Monoxide"
        chemicals["CO2"] = "Carbon Dioxide"
        chemicals["O2"] = "Dioxide"
        chemicals["H2"] = "DiHydrogen"
        chemicals["N"] = "Nitrogen"
        
    }
    
    @IBOutlet weak var field: UITextField!
    
    @IBOutlet weak var output: UILabel!
    @IBAction func buttonclicked(_ sender: Any) {
        /* let input = field.text!
        
        if(input == "")
        {
            output.text = "NOT FOUND"
        }
        else
        {
            output.text = chemicals[input]
        } */
        
        /* another way to accomplish this same thing is to do this */
        
        if(chemicals[field.text!] == nil)
        {
            output.text = "NOT FOUND"
        }
        else
        {
            output.text = chemicals[field.text!]
        }
        
    }
    
}

