Input related coding questions - SheCodes Athena - AI | SheCodes

Input related coding questions

👩‍💻 Technical question

How to use a switch case in JS?

🤖 SheCodes Athena says:

Answered in 9.26 seconds

In JavaScript, switch cases can be used to make decisions depending on the input. To set up a switch case, use the switch statement with an expression that evaluates to a value. Each case statement block provides the value to be compared with the switch statement's expression. The break statement is used to break out of the switch block after a case statement is matched. Here is an example in JavaScript:

js
Copy code
switch (num) { case 1: console.log('Number is 1'); // program break break; case 2: console.log('Number is 2'); // program break break; case 3: console.log('Number is 3'); // program break break; default: console.log('Number is not 1, 2, nor 3'); }

For more information on switch cases, see this Mozilla Docs article.

👩‍💻 Technical question

javascript sentence where to input variables

🤖 SheCodes Athena says:

Answered in 3.96 seconds
javascript
Copy code
let result = `The result of adding ${x + y} is ${x + y}.`

This statement uses string interpolation to create a string using variables x and y.

👩‍💻 Technical question

What is the argument in a function?

🤖 SheCodes Athena says:

Answered in 6.96 seconds

The arguments in a function are the input values that the function receives when called. The function uses these values as parameters and performs some operation or calculation based on them, then returns a result. These parameters can be of any type, including primitive data types such as numbers and strings, complex data types like objects and arrays, or other functions. For example, in the following function the argument (or parameter) is x:

javascript
Copy code
function addNumber(x){ return x + 10; }

When the addNumber function is called with a value of 5, the function returns 15 since x is equal to 5.

👩‍💻 Technical question

who to prompt a question on javascript

🤖 SheCodes Athena says:

Answered in 12.13 seconds

To prompt a question with JavaScript, you can use the prompt() method. prompt() opens a dialog box that prompts the user for input. For example, to prompt the user for their name, you can use the following code:

javascript
Copy code
var name = prompt("What is your name?");

This code opens a dialog box with the question "What is your name?" and stores the response in a name variable. For more information, please refer to the MDN docs.

👩‍💻 Technical question

how to create a new button?

🤖 SheCodes Athena says:

Answered in 7.08 seconds

Creating a new button depends on the programming language and framework you are using.

For example, in HTML and CSS you can add a button to your web page with the following code:

html
Copy code
<button type="button">Click Me!</button>

Additionally, you can use <input type="button" /> to add a button.

You can also use JavaScript or any other programming language to create a button. A general guide for JavaScript can be found here.

👩‍💻 Technical question

When submitting the form, alert the value of the password input

🤖 SheCodes Athena says:

Answered in 5.72 seconds

The following JavaScript code will alert the value of the password input when a form is submitted:

javascript
Copy code
document.querySelector('form').onsubmit = () => { alert(document.querySelector('input[type="password"]').value); }

More information about forms can be found in this MDN article.

👩‍💻 Technical question

how to declare an object with a prompt

🤖 SheCodes Athena says:

Answered in 4.94 seconds

In JavaScript, you can declare an object by asking for input from the user with a prompt, and assigning it to a variable.

Here's an example:

javascript
Copy code
let userObject = {}; let userInput = prompt("Please enter some data"); userObject.data = userInput;

This will store the user's input in the userObject variable.

👩‍💻 Technical question

how to declare value with a prompt

🤖 SheCodes Athena says:

Answered in 7.93 seconds

To declare value with a prompt in JavaScript, you'll need to use the prompt() method. This method takes in a string of text which will be used as the prompt to request input from the user.

Example code:

js
Copy code
let age = prompt("What is your age?"); console.log("You are "+age+" years old.");

Learn more about prompt() here.

👩‍💻 Technical question

how to create a prompt question with different spelling answers

🤖 SheCodes Athena says:

Answered in 18.61 seconds

You can create a prompt question with different spelling answers in most modern coding languages. A common example using JavaScript would be using the prompt() function to ask the user a question, followed by the if...else command to determine whether their response is spelled correctly. For example:

js
Copy code
let answer = prompt('What do you call a group of lions?'); if (answer === 'pride') { alert('You got it right!'); } else { alert('The correct spelling is "pride"'); }

That way, if the user spells the answer incorrectly, the if...else statement will alert them.

More information on prompt() and if...else statements can be found here:

👩‍💻 Code to be explained

function search(event) {
  event.preventDefault();
  let input = document.querySelector("#city-input");
  console.log(search.value);

  let h5 = document.querySelector("h5");
  if (input.value) {
    h5.innerHTML = `${input.value}...`;
  } else {
    h5.innerHTML = null;
    alert(`${input.value}...`);
  }
}
let form = document.querySelector("#search-form");
form.addEventListener("submit", search);

🤖 SheCodes Athena says:

Answered in 13.49 seconds

The code is written in JavaScript and makes use of DOM-related functions, such as document.querySelector to access and manipulate elements of the DOM.

The search() function is being triggered when the user submits the form, indicated by the event listener form.addEventListener set to submit. The purpose of the function is to take the value from the input with the id="city-input" and store it. The event.preventDefault() is then used to actually prevent the form from submitting, since we want to manage the input with JavaScript logic first.

When the value is stored, a conditional is used to check whether the input is empty or not. If it is empty, an alert of the value will be triggered. Otherwise, the innerHTML of h5 is changed to the value of the input.

This is how the code works overall.

For more information on how events work in JavaScript, you can refer to this link.

🤔 Frequently Asked Questions

If you have any other questions, you can easily reach out to us here

AI stands for Artificial Intelligence. AI bots are able to learn from conversations with users and expand their knowledge this way.

SheCodes Athena will help you with technical questions about your code using artificial intelligence to find the answer. Imagine a super powerful human who has memorized everything on the internet and can access that knowledge in a matter of seconds. 🤯

SheCodes Athena can answer most coding-related questions, even complicated ones! It can even find bugs in your code and tell you how to fix them in just a few seconds. Impressive, right?

Just remember we're still in testing mode so the AI may return strange or incorrect replies. Feel free to message us if this happens!

SheCodes Athena can only reply to coding-related technical questions. The same type of questions you would ask in the channels on Slack.

For questions that are not coding-related, write us here 😃

You should treat Athena like a SheCodes team member, so always be polite! 😊 Ask your questions as detailed as possible, just like you would do on Slack.

Here are some examples:

- Prettier isn't working on my VS Code. How do I fix this?

- How do I make bullet points with different colors using the list element?

- My code in Codesandbox is having some issues. Can you please tell me what the issue is? [Include the link to your Codesandbox]

For now, SheCodes Athena is limited to 5 questions per day for each student.

In that case, you can either ask SheCodes Athena a follow-up question, or you can post on the designated weekly channel on Slack!

Our technical assistants are still available on Slack and are always happy to help! 😍💪

Remember, questions are limited to 1000 characters.

- If you're working with an HTML file: Post a snippet of your code related to the issue you're having (just copy the code and paste it into the question box).

- If you're working with Codesandbox: Good news, you can just post the link to your Codesandbox and the AI Assistant will be able to view your code.

- If you have a longer question that would require an entire HTML file or more than 1000 characters, post it in the designated weekly channels on Slack! 😃

Athena was the Greek goddess of wisdom, among other elements. She received her name from the city of Athens, which she is known for protecting.

Much like the goddess Athena, SheCodes Athena is also incredibly wise and can solve complicated coding puzzles in a matter of seconds! 😍

Not likely. AI can automate tasks and make developers' jobs more efficient but it can't fully replace the human ability to deal with complex software. And AI will still require human developers to supervise and improve it further.

So developers may see their tasks change but they won't be replaced by AI. 👩‍💻🤝💻