• Variables for Input and Output







____________________________________________________________________________________________________________________________________________


Variables for Input and Output

  • Variables are usually used for values that are not constant, and are subject to change (user inputs, positions, whatever)

  • # define variables
    brawler = input("what's your favorite brawler (#)?:")
    
    # print variable
    print("Your favorite brawler is:", brawler)
    
    Your favorite brawler is: Mico
    
    %%html 
    
    <div>
      <!--(for demo purposes)-->
      <!--label for the input field-->
      <label for="brawlerInput">What's your favorite brawler (#)?</label>
      
      <!--input field to capture the user's age -->
      <input type="number" id="brawlerInput" name="brawlerInput">
      
      <!--button to submit the input value-->
      <button onclick="submitBrawler()">Submit</button>
    </div>
    
    <!--display the output-->
    <div id="output"></div>
    
    <script>
      // function to handle the submission of the age input
      function submitBrawler() {
        // get the value from the HTML input field
        let brawler = document.getElementById('brawlerInput').value;
        
        // log the value to the console
        console.log(brawler);
        
        // display the value on the page
        document.getElementById('output').innerText = `Your favorite brawler is: ${brawler}`;
      }
    </script>