Learning web development: Marking guides and questions

learning

(Chris Mills) #272

I am not sure what you mean. Do you want:

  1. A way to view in the devtools the JavaScript that creates a specific bit of generated HTML?
  2. A bit of JavaScript code that will grab the full HTML tree inside a specific element and prints it out?
  3. Something else?

(Mauro Di Bert) #273

Option 1 @chris! Because in a whole HTML i cannot know what part of the JS corresponds to a specific button, for instance. Is there anyway? Tks again!


(Chris Mills) #274

Not exactly, but kind of :wink:

If you have an event listener attached to a button, you’ll see a little “ev” button next to the button in the DOM inspector. Clicking this will ring up the event listener code associated with that button.

Apart from that, you just need to give your buttons sensible class names, and save references to them in sensible variable names in the JavaScript, so you know which bit relates to what. For example, if you have

<button class="subscribe-btn">Subscribe!</button>

You could then reference it in the JS with

var subscribeBtn = document.querySelector('.subscribe-btn');

If your page is complex and contains lots of buttons, it might be worth having a physical diagram stuck on your wall showing the UI, with the HTML and JS names of each button written next to each one.


(Mauro Di Bert) #275

Thanks @2alin! I was with a lot of things and could not thank you properly! And since I’m studying again, I come with this responde now! hehe. thanks man


(Mauro Di Bert) #276

Hi @chrismills! How are you!? I’m here with this code in where I can’t find why it doesn’t work. Could be because I didn’t define separately the pronoun? Tks man!

<script>
      function Person(first, last, age, gender, interests) {
        this.name = {
          'first': first,
          'last' : last
        };
        this.age = age;
        this.gender = gender;
        this.interests = interests;
        this.bio = function() {
          var firstString = this.name.first + ' ' + this.name.last + ' is ' + this.age + ' years old. ';
          if(this.gender === 'male') {
            firstString += 'He likes';
          } else if(this.gender === 'female') {
              firstString += 'She likes';
          } else {
              firstString += 'They like';
          }

          for(i = 0; i < this.interests.length; i++) {
            if(this.interests.length === 1) {
              firstString += this.interests[0] + '.';
            } else if(this.interests.length === 2) {
              firstString += this.interests[0] + ' and ' + this.interests[1] + '.';
            } else {
              for(i = 0; i < this.interests.length; i++) {
                if(i === this.interests.length -1) {
                  firstString += 'and ' + this.interests[i] + '.';
                } else {
                  firstString += this.interests[i] + ', ';
                }
              }
            }
          }

        alert(firstString);
        }
      }

      var person1 = new Person('Bob', 'Smith', 32, 'male', ['music', 'skiing']);
      var person2 = new Person('Robert', 'Diven', 12, 'male', ['games', 'more games']);
      var person3 = new Person('Sarah', 'White', 52, 'female', ['cosmethics']);
      var person4 = new Person('Meli', 'Dib', 32, 'female', ['music', 'skiing','cooking','going out with friends']);
      var person5 = new Person('Rob', 'Mark', 32, 'other', ['music', 'skiing']);

    </script>

(Chris Mills) #277

Hi Mauro!

I am very well thanks!

So, I am assuming you are talking about the bio() method logic that doesn’t work properly? Yes, this is a tricky one — it is annoying to deal with the cases of having one interest, two interests, and more than two interests. I had a play with this, and came up with the following method definition, which isn’t too horribly long and seems to work:

this.bio = function() {
  var firstString = this.name.first + ' ' + this.name.last + ' is ' + this.age + ' years old. ';
  if(this.gender === 'male') {
    firstString += 'He likes ';
  } else if(this.gender === 'female') {
      firstString += 'She likes ';
  } else {
      firstString += 'They like ';
  }

  for(i = 0; i < this.interests.length; i++) {
    if(i < this.interests.length - 1 && this.interests.length > 2) {
      firstString += this.interests[i] + ', ';
    } else if(i < this.interests.length - 1 && this.interests.length === 2) {
      firstString += this.interests[i] + ' ';
    } else if(i === this.interests.length - 1 && this.interests.length === 1) {
      firstString += this.interests[i] + '.';
    } else {
      firstString += 'and ' + this.interests[i] + '.';
    }
  }

alert(firstString);
}

Let me know if that solves your problem, or if you have other questions.

All the best.


(Mauro Di Bert) #278

Hi Chris! Thanks for the answer! I’m complicated finding time to study but I hope I could resume this week. I’ve write some code that works properly and found the error: I was using a loop (for) at the beginning that make no sense at all! hehe.

Thanks and have a nice day!


(MengChoon) #279

Hello,

I have been using this great site Learn Web Development to learn the basics of web development (Thank you!) and hence would like to find out if I can further use and reference the content to conduct a web development course at one of our local universities here in Singapore.

Would be grateful if I can hear from the community!

Best regards, Meng Choon


(Chris Mills) #280

Hello there! Under the license the tutorials are published under, you can reuse our content without any problem, as long as you give a credit to the original work. If you modify the content, you need to publish the modification under the same license as the original content.

Most of our code examples are CC0 licensed — you can use and modify them with no attribution.

For more on the licenses we publish things under, see https://developer.mozilla.org/en-US/docs/MDN/About#Copyrights_and_licenses.

Please tell me more about the course — I am excited to hear about it!


(MengChoon) #281

Hi Chris,

Thank you for your kind response and sharing the info. I am engaged by the university to develop the course curriculum & content for a undergraduate level web development course. My intent is to teach students who has little background on web concepts to pick up practical programming skills within a 35-40 hrs learning hours period and equip them with the fundamentals to code and build a full stack MVC app.

I have been using the content to introduce web programming to our entry level staff in my web development company and had found your resources here very practical and terse and this has help to enable our staff to learn and contribute practically to our team quickly - something that I really appreciate!


(Chris Mills) #282

Sounds like a great course, and I’m so happy to hear you are finding the material useful. Please let me know if you need any help.

In terms of MVC, we have this: https://developer.mozilla.org/en-US/Apps/Fundamentals/Modern_web_app_architecture/MVC_architecture

It is a bit out of date. My colleague Irene is currently updating it to use React instead of Ember, as React is a bit more popular.


(MengChoon) #283

Thank you again for sharing more info. I’ll definitely take a look at it and will update it to apply the concepts to the python Flask framework :slight_smile:


(Acout Payn) #284

I just wanna say thanks!
I once used the school’s firefox browser,I’ve known this learning web development marking guides,then I started my learning journey.I will create a beautiful and creative website of mine.
To have my own place is my dream,thank you mozilla!Thank you volunteers!When I am strong enough,I will join your family.
I have seen your source code and compare with my code,I have already corrected my wrong code.


(Chris Mills) #285

Thanks for the feedback — I am so glad you are finding our material helpful!


(Jimduan98) #286
  • my code

<!DOCTYPE html>
<html lang="en">
<head>
		<meta charset="utf-8">
		<link rel="stylesheet" type="text/css" href="./letter-text.css">
		<title>Test</title>
</head>
<body>
	<header>
		<div class="sender-column">
			<p><strong><em>Dr. Eleanor Gaye</em></strong></p>
			<p><em>Awesome Science faculty</em></p>
			<p><em>University of Awesome</em></p>
			<p><em>Bobtown, CA 99999,</em></p>
			<p><em>USA</em></p>
			<p><em><strong>Tel:</strong> 123-456-7890</em></p>
			<p><em><strong>Email:</strong> no_reply@example.com</em></p>
			<p><time datetime="2016-01-20">20 January 2016</time></p>
		</div>

		<address>
			<p><em><strong>Miss Eileen Dover</strong></em></p>
			<p><em>4321 Cliff Top Edge</em></p>
			<p><em>Dover, CT9 XXX</em></p>
			<p><em>UK</em></p>
		</address>


		<h1>Re: Eileen Dover university application</h1>
	</header>

	<main>
		<p>Dear Eileen,</p> 

		<p>Thank you for your recent application to join us at the University of Awesome's science faculty to study as part of your <abbr title="Doctor of Philosophy">PhD</abbr> next year. I will answer your questions one by one, in the following sections.</p>
		
		<h2>Starting dates</h2>
		
		<p>	We are happy to accommodate you starting your study with us at any time, however it would suit us better if you could start at the beginning of a semester; the start dates for each one are as follows:</p>

		<ul>
			<li>First semester: <time datetime="2016-09-09">9 September 2016</time> </li>
			<li>Second semester: <time datetime="2017-01-15">15 January 2017</time></li>
			<li>Third semester: <time datetime="2017-05-02">2 May 2017</time></li>
		</ul>
		

		<p>Please let me know if this is ok, and if so which start date you would prefer.</p> 

		<p>You can find more information about <a href="#">important university dates</a> on our website.</p>
		

		<h2>Subjects of study</h2>

		<p>	At the Awesome Science Faculty, we have a pretty open-minded research facility — as long as the subjects fall somewhere in the realm of science and technology. You seem like an intelligent, dedicated researcher, and just the kind of person we'd like to have on our team. Saying that, of the ideas you submitted we were most intrigued by are as follows, in order of priority:</p>

		<ol>
			<li>Turning H2O into wine, and the health benefits of Resveratrol (C<sub>14</sub>H<sub>12</sub>O<sub>3</sub>.)</li>
			<li>Measuring the effect on performance of funk bassplayers at temperatures exceeding 30°C (86°F), when the audience size exponentially increases (effect of 3 &times; 10<sup>3</sup> increasing to 3 &times; 10<sup>4</sup>.)</li>
			<li><abbr title="HyperText Markup Language">HTML</abbr> and <abbr title="Cascading Style Sheets">CSS</abbr> constructs for representing musical scores.</li>
		</ol>

		<p>So please can you provide more information on each of these subjects, including how long you'd expect the research to take, required staff and other resources, and anything else you think we'd need to know? Thanks.</p>


		<h2>Exotic dance moves</h2>
		
		<p>Yes, you are right! As part of my post-doctorate work, I did study exotic tribal dances. To answer your question, my favourite dances are as follows, with definitions:</p>

		<dl>
			<dt>Polynesian chicken dance</dt>
			<dd>A little known but very influential dance dating back as far as 300<abbr title="Before Christ">BC</abbr>, a whole village would dance around in a circle like chickens, to encourage their livestock to be "fruitful".</dd>
			<dt>Icelandic brownian shuffle</dt>
			<dd>Before the Icelanders developed fire as a means of getting warm, they used to practice this dance, which involved huddling close together in a circle on the floor, and shuffling their bodies around in imperceptibly tiny, very rapid movements. One of my fellow students used to say that he thought this dance inspired modern styles such as Twerking.</dd>
			<dt>Arctic robot dance</dt>
			<dd>An interesting example of historic misinformation, English explorers in the 1960s believed to have discovered a new dance style characterized by "robotic", stilted movements, being practiced by inhabitants of Northern Alaska and Canada. Later on however it was discovered that they were just moving like this because they were really cold.</dd>
		</dl>


		<p>For more of my research, see my <a href="#">exotic dance research page</a>.</p>

		<p>Yours sincerely,</p>
		&nbsp;
		&nbsp;
		&nbsp;
		&nbsp;
		<p>Dr Eleanor Gaye</p>

	</main>
	
	<footer>
		<p>University of Awesome motto: <q cite="#">Be awesome to each other.</q> -- Bill S Preston, Esq</p>
	</footer>
</body>
</html>

(Chris Mills) #287

Hi there @jimduan98!

I have looked over your code, and you have got most of this right. There are a few small bits to pick up on:

  1. You don’t need to put each line of the addresses in a separate <p> element — you could just surround each one in a single paragraph, and then use <br> elements to create line breaks as required. This would be better for semantics, as each one is a single paragraph, not multiple paragraphs.
  2. The <address> element is used to markup contact details of the person who authored the webpage. So you could argue that Eleanor’s address could be put in an <address> element, but not Eileen’s address.
  3. “H2O” -> The “2” needs to be inside a <sub> element.
  4. You don’t need lots of &nbsp;s after the “Yours sincerely,” line.
  5. The quotation is probably better written as <p>University of Awesome motto: <q>Be excellent to each other.</q> -- <cite>Bill S Preston, <abbr title="Esquire">Esq</abbr></cite></p>, but yours is OK.