Artificial Intelligence Assignment

Using JavaScript Language

Day 4

Now let's get the code to make this happen. Add this code to the end of your html project file - after the input two arrays section.

Our program will not run just yet. We need to ad more code: the main algorithm.We will examine it in just a few minutes.

Day 5

Explanation of the Constraint code

The constraint code for Anna creates an array based on the number of items in the array. There 15 numbers, 9-23. The length of the array is 15. The array Anna[a] is assigned to the letter x. The first loop produces the following results

Next array output

The last section produces

If you add some window.alerts to the code you can see first hand how this code, gets the first hours, deletes the unavailable hours and the adds the rest of the hours after the deleted hours. The third window.alert shows the deleted hours

Day 6

The main algorithm is added at the end of your project. Save and test. The document.writeln has been added so that the information you desire is printed onto the html document as well as the console. As you have probably noticed the variables a, b, c, d, e and f were used to represent each employee as well as the variables v, w, x, y, z and z1.

Our example is a simple AI problem-solving algorithm based on data contained in the arrays. The constraints eliminate some unavailable hours. The main goal of the program is stated If (g1(Anna[v], Betty[w], Cara[x], Donna[y], Jerry[z], Ashley[z1])). If all these conditions are true then the solution is displayed in the console.log stating that all these folks can meet at particular times.

Debugging Tips/Completed project code

JavaScript can be tricky, especially the curly braces. When using Notepad++, if you click on a beginning curly brace, it turns red and the corresponding ending brace also turns red. This is a good way to check if you have the correct number of braces surrounding the statements. This also works with parentheses.

The tutorial link below has some very useful information about debugging javaScript.

Debugging javaScript in Chrome Dev Tools

There a number of other ways to debug javaScript code. The first method uses a breakpoint that is set in your code. Let's try this method using our AI program. Suppose we are trying to find out what is in Anna[a] array. We can key in some lines In Notepad++ setting a breakpoint using debugger; as a line of code followed by a console.log Anna([a]);. Insert these two lines into your original code as shown below.

The second method involves setting the breakpoint using DevTools.