Professional Documents
Culture Documents
Proyecto MVC Cordova
Proyecto MVC Cordova
Proyecto MVC Cordova
Subject Page
Introduction ......................................................................................................... 1
Conclusion .......................................................................................................... 8
JavaScript Exercises........................................................................................... 9
JS Variables .................................................................................................... 9
JS Operators .................................................................................................. 11
i
JS Functions.................................................................................................. 14
JS Objects ..................................................................................................... 16
JS Variables .................................................................................................. 18
JS Operators ................................................................................................. 19
JS Functions.................................................................................................. 21
JS Objects ..................................................................................................... 22
ii
Index of figures
Figure Page
iii
Figure 26 JS Functions Exercise 2 ................................................................... 14
Figure 27 JS Functions Exercise 3 ................................................................... 15
Figure 28 JS Functions Exercise 4 ................................................................... 15
Figure 29 JS Functions Completed Exercises .................................................. 15
Figure 30 JS Objects Exercise 1 ....................................................................... 16
Figure 31 JS Objects Exercise 2 ....................................................................... 16
Figure 32 JS Objects Exercise 3 ....................................................................... 17
Figure 33 JS Objects Completed Exercises ...................................................... 17
Figure 34 JavaScript Completed Exercises ...................................................... 17
iv
Introduction
Follow along as we guide you through each stage, from the foundational setup to
the implementation of the Model-View-Controller architecture, ensuring a
seamless and organized approach to Android development.
1
Establish the workspace
We will be utilizing Visual Studio Code as our primary code editor, and Apache
Cordova specifically geared towards Android development. To initiate this
process, we will create a dedicated folder within your system for your project's
files.
Open your terminal and navigate to the directory where you want to store your
project. Once there, execute the following command to create a new folder for
your project:
This creates the fundamental directory structure for your project. We will proceed
with further steps to configure it for development.
Then point out from the terminal that you are now working on the folder of the app
created with Cordova, using the cd command:
2
Adding the Android Platform
With the workspace established, the next step involves incorporating the target
platform for your application. In this case, we will be focusing on Android
development.
To specify Android as the platform for your project, use the following command in
your terminal within the project directory:
3
Installation of the resources
Once you have the development environment set up, we will incorporate the
necessary resources to enhance the user interface of your application.
Installation of bootstrap
Installation of jQuery
4
Figure 6 Installing jQuery to the project
To view the project on the computer we must run the project in the search
browser, with the next command:
5
Implementing the Model-View-Controller
One time we have all the necessary resources installed we must move it to the
correctly folders to follow the MVC:
With one level less than 'www' we must create three folders with the following
names: Models, Views, and Controllers.
Also create the public folder at the same level as Models, Views, and Controllers
to add the folder of ‘css’, ‘js’, and ‘img’.
Also, if you do not know where the files are downloaded, all files downloaded with
the terminal are saved in the “node_modules” folder.
6
Implementing Partial Views
Now we need to modify certain files by adding, changing, and deleting lines, we
are starting with “index.js”. What we are doing here is writing a function to load a
partial view.
Finally, we must change the main index, called “index.html”, by removing a line
where a safety line existed, changing, and adding file references, and adding the
other part of the function to load the partial view. Further down in the Cordova
policy paragraph there is a security line, we must eliminate or comment on it, it
could work with any problem.
7
Conclusion
The incorporation of essential resources like Bootstrap and jQuery enhances the
user interface, while the detailed instructions on implementing partial views and
organizing project folders contribute to optimizing functionality. This guide equips
developers with the knowledge and tools needed for a seamless and efficient
Android development experience.
8
JavaScript Exercises
JS Variables
9
Figure 14 JS Variables Exercise 4
10
JS Operators
11
Figure 20 JS Operators Exercise 4
12
JS Data Types
13
JS Functions
14
Figure 27 JS Functions Exercise 3
15
JS Objects
16
Figure 32 JS Objects Exercise 3
17
JavaScript Exercises (text)
JS Variables
Exercise 1.- Create a variable called carName, assign the value Volvo to it.
Answer: let x = 50
Exercise 3.- Display the sum of 5 + 10, using two variables: x and y.
Answer:
let x = 5;
let y = 10;
document.getElementById(“demo”).innerHTML = x + y;
Exercise 4.- Create a variable called z, assign x + y to it, and display the result in
an alert box.
Answer:
let x = 5;
let y = 10;
let z = x + y;
alert (z);
18
Exercise 5.- On one single line, declare three variables with the following names
and values:
firstName = "John"
lastName = "Doe"
age = 35
JS Operators
Exercise 4.- Use the correct assignment operator that will result in x being 15
(same as x = x + y).
Answer:
x = 10;
y = 5;
19
x += y;
Exercise 5.- Use the correct assignment operator that will result in x being 50
(same as x = x * y).
Answer:
x = 10;
y = 5;
x *= y;
JS Data Types
Exercise 1.- Use comments to describe the correct data type of the following
variables:
3. const x = {
firstName: “John”,
lastName: “Doe”
}; // ________________
20
JS Functions
Answer:
function myFunction() {
alert(“Hello World!”);
myFunction();
Answer:
function myFunction() {
alert(“Hello World!”);
Answer:
function myFunction() {
return “Hello”;
document.getElementById(“demo”).innerHTML = myFunction();
21
Exercise 4.- Make the function display "Hello" in the inner HTML of an element
with the ID "demo".
Answer:
function myFunction() {
document.getElementById(“demo”).innerHTML = “Hello”;
JS Objects
Exercise 1.- Alert "John" by extracting information from the person object.
Answer:
const person = {
firstName: “John”,
lastName: “Doe”
};
alert (person.firstName);
Exercise 2.- Add the following property and value to the person object: country:
Norway.
Answer:
const person = {
firstName: “John”,
lastName: “Doe”,
22
country: “Norway”
};
Exercise 3.- Create an object called person with name = John, age 50.
Answer:
const person = {
};
alert(person.name + “ is “ + person.age);
23