• jollyyau

Week 5: Strings and Arrays


Homework for Assignment 2:

  • Creative concepts, everyone got stuff to work.

  • More attention to DESIGN of your pages - linking your design decisions to yourcreative concepts.

  • Make sure you utilise the skills covered in class - Assignment 2 must includeArrays, Strings and animations.

  • Speak to your code to demonstrate you understand what you have implemented -screenshot it or bring it up when looking at the page.

  • Try to speak clearly, use slides and order your presentation logically.

Javascript Terminology:

  • Statements

  • discrete lines of code that is run together

  • e.g. document.getElementById("demo").innerHTML = "I'm afraid. I'm afraid, Dave. Dave, my mind is going";

  • Variables

  • named containers for data

  • Global: Can be defined anywhere in the JaveScript code

  • Local: Can only be used within a function where it is defined.

  • e.g.

  • var x = 1;

  • Functions

  • blocks of code designed to do something

  • e.g.

  • function myFunction(p1, p2) { return p1 * p2;} document.getElementById("demo").innerHTML = myFunction(4, 3);

  • Properties

  • values associated with an objects, and can be accessed by "object.property.syntax"

  • e.g.

  • var car = {type:"Fiat", model:"500", color:"white"}; document.getElementById("demo").innerHTML = car.type + " " + car.model;

  • Methods

  • actions that can be performed with objects

  • e.g.

  • var message = "Hello world!"; var x = message.toUpperCase();

  • String

  • Strings are datatype used for storing text, numbers and emoji

  • They are a kind of variable and so are declared in the same way as other variables.

  • e.g.

  • var comment = "This is a string";

  • They can be of any length and the .length property returns the length in characters.

  • e.g.

  • var txt = "QWERTYUIOPASDFGHJKLZXCVBNM"

  • var sln = txt.length;

Methods of Manipulating Strings

  • search () locates particular value and returns position

  • e.g.

  • var str = "Please locate where 'locate' occurs!"

  • var pos = str.search("locate");

  • slice () extract parts of string

  • e.g.

  • var str = "Apple, Banana, Kiwi";

  • var res = str.slice(7,13);

  • Result: Banana

  • concat () joins two or more strings

  • e.g.

  • var text1 = "Hello";

  • var text2 = "World";

  • var text3 = text1.concat(" ", text2);


Recent Posts

See All

Week 11 + 12: Presentations II

These two weeks, we are presenting our web experiments that include the following: Map APIs Canvas Data Input It was very challenging for me, because I didn't know very much about coding at all. I sta

jollyyau.design © 2020

  • LinkedIn - White Circle
  • Facebook - White Circle
  • Instagram - White Circle