Learn Form Validation by Building a Calorie Counter - Step 10

How do I select the first option be default can someone help me please ?.

Your code so far

<!-- file: index.html -->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link rel="stylesheet" href="styles.css" />
    <title>Calorie Counter</title>
  </head>
  <body>
    <main>
      <h1>Calorie Counter</h1>
      <div class="container">
        <form id="calorie-counter">
          <label for="budget">Budget</label>
          <input
            type="number"
            min="0"
            id="budget"
            placeholder="Daily calorie budget"
            required
          />
          <fieldset id="breakfast">
            <legend>Breakfast</legend>
            <div class="input-container"></div>
          </fieldset>
          <fieldset id="lunch">
            <legend>Lunch</legend>
            <div class="input-container"></div>
          </fieldset>
          <fieldset id="dinner">
            <legend>Dinner</legend>
            <div class="input-container"></div>
          </fieldset>
          <fieldset id="snacks">
            <legend>Snacks</legend>
            <div class="input-container"></div>
          </fieldset>
          <fieldset id="exercise">
            <legend>Exercise</legend>
            <div class="input-container"></div>
          </fieldset>

<!-- User Editable Region -->

          <div class="controls">
            <span>
              <label for="entry-dropdown">Add food or exercise:</label>
              <select id="entry-dropdown" name="options">
              <option value="breakfast">Breakfast</option>
              <option value="lunch">Lunch</option>
              <option value="dinner">Dinner</option>
              <option value="snacks">Snacks</option>
              <option value="exercise">Exercise</option>
              </select>
              <button type="button" id="add-entry">Add Entry</button>
            </span>
          </div>

<!-- User Editable Region -->

        </form>
      </div>
    </main>
  </body>
</html>
/* file: styles.css */
:root {
  --light-grey: #f5f6f7;
  --dark-blue: #0a0a23;
  --fcc-blue: #1b1b32;
  --light-yellow: #fecc4c;
  --dark-yellow: #feac32;
  --light-pink: #ffadad;
  --dark-red: #850000;
  --light-green: #acd157;
}

body {
  font-family: "Lato", Helvetica, Arial, sans-serif;
  font-size: 18px;
  background-color: var(--fcc-blue);
  color: var(--light-grey);
}

h1 {
  text-align: center;
}

.container {
  width: 90%;
  max-width: 680px;
}

h1,
.container,
.output {
  margin: 20px auto;
}

label,
legend {
  font-weight: bold;
}

.input-container {
  display: flex;
  flex-direction: column;
}

button {
  outline: none;
  cursor: pointer;
  text-decoration: none;
  background-color: var(--light-yellow);
  border: 2px solid var(--dark-yellow);
}

.clear {
  background-color: var(--light-pink);
  color: var(--dark-red);
  border-color: var(--dark-red);
}

button,
input,
select {
  min-height: 24px;
  color: var(--dark-blue);
}

fieldset,
label,
button,
input,
select {
  margin-bottom: 10px;
}

.output {
  border: 2px solid var(--light-grey);
  padding: 10px;
  text-align: center;
}

.hide {
  display: none;
}

.output span {
  font-weight: bold;
  font-size: 1.2em;
}

.surplus {
  color: var(--light-green);
}

.deficit {
  color: var(--light-pink);
}
/* file: script.js */

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36

Challenge Information:

Learn Form Validation by Building a Calorie Counter - Step 10

THe instructions say

Set the Breakfast option as the selected option.

You need to use the selected attribute

1 Like

How do I do that ? .

1 Like

like any other attribute, you write it in the opening tag. The selected attribute doesn’t want any value, so you just write selected in the opening tag

2 Likes

I am in the same exercise and I don’ t understood where is the problem in my code

<select>
  <option value="breakfast" selected>Breakfast</option>
  <option value="lunch">Lunch</option>
  <option value="dinner">Dinner</option>
  <option value="snacks">Snacks</option>
  <option value="exercise">Exercise</option>
</select>
1 Like

Hey @MaryGothic
good work so far ,your select element seem to be missing an id and name attribute otherwise everything else looks ok

Next time I would advise you create your own topic so that you may get help

Happy coding

          <div class="controls">
            <span>
              <label for="entry-dropdown">Add food or exercise:</label>
              <select id="entry-dropdown" name="options">
                <fieldset value="breackfast" id="breackfast">Breakfast</fieldset>
                <fieldset value="lunch" id="lunch">Lunch</fieldset>
                <fieldset value="dinner" id="dinner">Dinner</fieldset>
                <fieldset value="snacks" id="snacks">Snacks</fieldset>
                <fieldset value="exercise" id="exercise">Exercise</fieldset>

              </select>
              <button type="button" id="add-entry">Add Entry</button>
            </span>
          </div>

like this?

Almost there the field set elements need to option element ,then get rid of the id attributes inside the field sets

Just use option elements like so

<option></option>

Replace them with the fieldset

Hope you understand

`          <div class="controls">
            <span>
              <label for="entry-dropdown">Add food or exercise:</label>
              <select id="entry-dropdown" name="options">
                <option value="breackfast" id="breackfast">Breakfast</option>
                <option value="lunch" id="lunch">Lunch</option>
                <option value="dinner" id="dinner">Dinner</option>
                <option value="snacks" id="snacks">Snacks</option>
                <option value="exercise" id="exercise">Exercise</option>

              </select>
              <button type="button" id="add-entry">Add Entry</button>
            </span>
          </div>`

Get rid of these id attributes and make sure to add selected attribute to the first option that contains breakfast

Get rid of id attributes for all the options

1 Like

Thank you! Also I wrote bad “breaCkfast”! xD :rofl:

1 Like

It happens to us all the time keep up the good work!! :smile: :smile: :smile: :smile:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.