Fall 2024 - P1
Big Idea 3 | .1 | .2 | .3 | .4 | .5 | .6 | .7 | .8 | .10 |
3.1 Variables and Strings
Team Teach String Operations
- Variables for Input and Output
____________________________________________________________________________________________________________________________________________
Variables for Input and Output
# 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>