The prompt and variables.
The prompt command is also very easy just like the message_box command.
It works almost the same way.
Code example:
The prompt works like so:
prompt('prompt question','default string')
So go and try it.
But why would we need this?
And how do we use it?
Well why we would use it is that we can ask a person for input and use this everywhere.
How to use it is with variables like so:
Code example:
So we used alert to display but we forgot the quotes!
No we did not forget them.
When using variables we need to remove them so that it lets the computer know it is a variable.
When using quotes that means that we are displaying a string.
If you go and try the alert with the quotes it is gonna display the word: name
but if we do not add the quotes it is gonna display the variable content.
Now for how we use variables.
You saw that example so you know we can assign it using the prompt command.
We can also assign it whenever we want.
Code example:
So variables can be assigned anywhere.
We can assign a string, a number or a boolean to the variable.
Even assign a variable another variable!
You can also use global variables.
Code example:
Global variables are global all across the code.
But its not so useful at the moment.
It works almost the same way.
Code example:
- prompt('what is your name?','no name')
The prompt works like so:
prompt('prompt question','default string')
So go and try it.
But why would we need this?
And how do we use it?
Well why we would use it is that we can ask a person for input and use this everywhere.
How to use it is with variables like so:
Code example:
- name=prompt('What is your name?','no name')
- message_box(name)
So we used alert to display but we forgot the quotes!
No we did not forget them.
When using variables we need to remove them so that it lets the computer know it is a variable.
When using quotes that means that we are displaying a string.
If you go and try the alert with the quotes it is gonna display the word: name
but if we do not add the quotes it is gonna display the variable content.
Now for how we use variables.
You saw that example so you know we can assign it using the prompt command.
We can also assign it whenever we want.
Code example:
- variable=0
- variable2='string'
- variable3=true
So variables can be assigned anywhere.
We can assign a string, a number or a boolean to the variable.
Even assign a variable another variable!
You can also use global variables.
Code example:
- global.variable='global string'
Global variables are global all across the code.
But its not so useful at the moment.