Aide exercice javascript

Signaler
Messages postés
19
Date d'inscription
mardi 10 juillet 2007
Statut
Membre
Dernière intervention
24 novembre 2013
-
Messages postés
13616
Date d'inscription
jeudi 13 février 2003
Statut
Membre
Dernière intervention
15 octobre 2013
-
bonjour,

Je viens de récuperer des cours de javascript d'une université anglaise, et il y une série d'exercices où il n'y a pas les solution. J'apprend par moi même et je cherche des personne qui veulent bien faire les exercice et me les renvoyer pour que je puisse corriger, voir votre facon de faire, m'améliorer.

Pour ceux qui veulent voici les énnoncés.

question 1
(i) Make a copy of the file M150_TMA03_2007J_Q1.html, which we have supplied as a template for this question, and rename it M150_TMA03_2007J_Q1(i).html. Using this template, write a JavaScript program that prompts the user to enter 1 if they want to register as a new customer; and 2 if they are an established customer. If the user inputs anything other than 1 or 2, the system prompts them to try again. Do not use a loop: if the input is still not valid after two tries, the program does not produce any output.
Once a user has successfully entered 1 or 2, your system should print a welcome message. New customers should get the message “WELCOME – WE WILL SET UP YOUR ACCOUNT DETAILS NOW”; established customers will just get the message “SHOP UNTIL YOU DROP”.
Insert a copy of your JavaScript code into your solution document. [5]
(ii) Make a copy of the file M150_TMA03_2007J_Q1(i).html and rename it M150_TMA03_2007J_Q1(ii).html.
Amend this file to include code for the entry of customer details. Individuals starting a new account must enter the following data: first name, second name and a password of their own choice.
Passwords must be at least 7, and no more than 15, characters long (there is no restriction on the type of characters allowed). If users enter a password that is invalid according to this rule then the program displays an explanatory message, telling the user how many characters the password entered actually had, and prompts them repeatedly until a valid password is entered.
Test your program with the name Orson Welles and passwords Kane12, CitizenKane12345.
Insert a copy of your JavaScript code into your solution document followed by a screenshot of the browser window showing the result of your test with the password Kane12. [9]
(iii) Make a copy of the file M150_TMA03_2007J_Q1(ii).html and rename it M150_TMA03_2007J_Q1(iii).html.
Amend this file so that your program allocates the new customer a customer code. The customer code is a string made up of the first letter of the first name, plus the first letter of the second name, and a dash. Thus, a customer with the following details:
First name: Orson
Second name: Welles
Password: CitizenKane
will have the customer code:
OW-
Your program should write the first name, the second name and the customer code to the screen. Test your program on the data given above.
Insert a copy of your JavaScript code into your solution document followed by a screenshot of the browser window showing the result of your test. [4]
(iv) Make a copy of the file M150_TMA03_2007J_Q1(iii).html and rename it M150_TMA03_2007J_Q1(iv).html.
Amend this file so that your program displays what the customer has just entered. Add code that writes out a welcome message, followed by the customer’s first name, second name and password: the password should only display the first and last characters; otherwise asterisks should replace the actual characters.
Test your program on the inputs you used in part (iii) above. The output from your program should resemble Figure 1 on the following page.
M150 TMA03 Question 1
WELCOME – WE WILL SET UP YOUR ACCOUNT DETAILS NOW
WELCOME TO SOFASPEND
Your details are as follows: Customer Code: OW-
First name: Orson
Second name: Welles
Password: C*********e
Figure 1 Example of a welcome message followed by customer details
Insert a copy of your JavaScript code into your solution document followed by a screenshot of the browser window showing the result of your test. [7]

Question 2

(i) Make a copy of the file M150_TMA03_2007J_Q2.html, which we have supplied as a template for this question, and rename it M150_TMA03_2007J_Q2(i).html. Using this template, write code that will log a customer in. For the convenience of their customers, SofaSpend have simplified the log-in process, so that the system prompts them to enter their password only (instead of asking for both user name and password as is generally the case). Therefore, your code will just need to request a password from the user and check it against the passwords in the password array. If a match is not found, the system simply asks for the password again, and continues to do so until a match is found. Once a match has been found, a welcome message is displayed, which includes the customer code and should look like this:
Welcome, Customer il-77. Ready to start shopping?
Test your program using the password onlyme.
NOTE: You might find it useful for the later parts of this question if you store the customer’s index number, the position he or she occupies in the customer arrays. We have provided a variable you can use for this purpose in M150_TMA03_2007J_Q2.html.
Insert a copy of your JavaScript code into your solution document followed by a screenshot of the browser window showing the result of your test. [7]
(ii) Make a copy of the file M150_TMA03_2007J_Q2(i).html and rename it M150_TMA03_2007J_Q2(ii).html. Amend this file so that the program displays the goods on offer: for each product, we want to see the number it is in the list of products (the item number); the product code; the description; the price; and number in stock. Write code that will produce an output resembling Figure 2 on the following page. Don’t waste time on trying to get everything neatly aligned. A ragged-looking output is perfectly acceptable.
Here are the exciting products we have available today: Item---Code--------Product-------------------------Price- --Stock ========================================== 0 --- a-23-009 -- Superslurry electric blender --- 45 ---- 200
1 ---k-246-07 -- Apple-iPod (second-hand) ---- 50 -- --- 0
2 ---d-555-01 -- CoziNap nylon duvet tog 2 ------ 15 ----- 2
3 ---n-87-012 -- Headbanger mini hi-fi 20W ----- 25 --- 500
4 --- u-521-08 -- MagiBoot shoe cleaning kit ----- 75 - --- 500
5 ---t-99-002 -- The PushmiPulu lawnmower ------ 7 ----- 15
Figure 2 SofaSpend product list
Test your program using the password onlyme.
Insert a copy of your JavaScript code into your solution document followed by a screenshot of the browser window showing the result of your test. [5]
(iii) Make a copy of the file M150_TMA03_2007J_Q2(ii).html and rename it M150_TMA03_2007J_Q2(iii).html. Amend this file so that the program allows the customer to order some products. The program should take the user through the following process:
1 the customer is prompted to enter how many different products they want to purchase (you can assume the customer will input a whole number);
2 For each product, the customer is then prompted to

enter the item number from the column headed Item in Figure 2, (e.g. they would enter 3 to choose product n-87-012)

enter how many units of that product they require
(e.g. 6 Headbanger hi-fis).
3 Step 2 is then repeated until the number of products the user chose in Step 1 is reached.
When the ordering process is complete, the program prints out the order.
You can assume that the customer will always enter valid product numbers and will never duplicate orders for the same product
(e.g. order, say, iPods twice).
Store the details of the customer’s order in two parallel arrays, the first storing the index number of the products the customer has chosen, the second storing the quantities of each product. Thus, if the customer wants to buy three different products, then each array will contain three elements. So, for example, for the order illustrated in Figure 2, the two arrays would contain values as follows
orderProductArray [1, 3, 5]
orderQuantityArray [2, 1, 3]

Section 2.6 of Unit 8, pp. 18–21 tells you how to set up an array and add values to it.
The final part of the output from your program should resemble Figure 3. (Again, don’t waste time trying to get everything aligned.)
Here is your order il-77 Code--------Product------------------------Number----------Price Each ======================================== k-246-07 -- Apple - iPod (second-hand) ----- 2 ------------ 50
n-87-012 --Headbanger mini hi-fi 20W ------ 1 ------------ 25
t-99-002 --The PushmiPulu lawnmower ----- 3 ------------ 70
Figure 3 Example customer order
Test your program with the password onlyme and the three product numbers for the products shown in Figure 3.
Insert a copy of your JavaScript code into your solution document followed by a screenshot of the browser window showing the result of your test. [12]
(iv) Make a copy of the file M150_TMA03_2007J_Q2(iii).html and rename it M150_TMA03_2007J_Q2(iv).html. Amend this file so that the program processes the arrays in which you are storing the customer order to add up the full cash amount of the purchase. The program writes this value to the screen.
The final part of the output from your program should resemble Figure 4 (again you can ignore alignment):
Here is your order il-77 Code--------Product------------------------Number----------Price Each
======================================= k-246-07 -- Apple - iPod (second-hand) ----- 2 ------------ 50
n-87-012 --Headbanger mini hi-fi 20W ------ 1 ------------ 25
t-99-002 --The PushmiPulu lawnmower ----- 3 ------------ 70
The total value of your order is £335 Thank you.
Your order is being processed.
Figure 4 Example customer order
Test your program using the same data as in Question 2(iii).
Insert a copy of your JavaScript code into your solution document followed by a screenshot of the browser window showing the result of your test. [6]

Question 3

(i) Make a copy of the file M150_TMA03_2007J_Q3.html, which we have supplied as a template for this question, and rename it M150_TMA03_2007J_Q3(i).html. The button Show all stock holdings on the main form causes the form to display the levels of main stock and of received stock for each product, which are contained in the parallel arrays productStock and receivedLevels. Pressing the button calls an event handler function showStockLevels(), which fills in the appropriate fields in the form by extracting data from the two arrays and writing it into the relevant fields on the form. Write this function. Test the function by pressing the button Show all stock.[5]
Insert a copy of your function into your solution document followed by a screenshot of the browser window showing the result of your test.
(ii) Make a copy of the file M150_TMA03_2007J_Q3(i).html and rename it M150_TMA03_2007J_Q3(ii).html. Clicking the button Add receipts to stock calls an event handler function that updates the arrays productStock and receivedLevels, by adding the receipts for each product to the value in productStock, and then setting the values receivedLevels to 0. The system should then display the new totals. Write this function. Test the function by pressing the button Add receipts to stock. [5]
Insert a copy of your function into your solution document followed by a screenshot of the browser window showing the result of your test.
(iii) Make a copy of the file M150_TMA03_2007J_Q3(ii).html and rename it M150_TMA03_2007J_Q3(iii).html. Clicking the button Calculate totals calls a function calculateTotals(), which will process the stock arrays to calculate the level of main stock, the level of received stock, the total cash value of all stock, main and received, and the tax payable on the stock. A special tax loophole that SofaSpend is exploiting is that tax on main stock is 8% but tax on received stock is 6%. Write the function calculateTotals(). Test the function by pressing the button Show all stock followed by the button Calculate totals. [10]
Insert a copy of your function into your solution document followed by a screenshot of the browser window showing the result of your test.

Pour la question 1 le code de départ ne comprend rien du tout pour la question 2 voici le code M150_TMA03_2007J_Q2.HTML

<HTML>
<HEAD>    M150 TMAO3 Question 2
<TITLE>SOFASPEND - IN THE BEST POSSIBLE TASTE!</TITLE>

<SCRIPT

language="JavaScript"
type="text/javascript">    

// These are arrays containing customer data

var customerCodes = ['lt-17', 'gw-3', 'lg-9', 'il-77', 'fy-32'];

var customerPasswords = ['password', 'bluesky', 'dr45gr6', 'onlyme', 'lothlorien'];

// These are arrays containing product data

var productCodes = ['a-23-009', 'k-246-07', 'd-555-01', 'n-87-012', 'u-521-08', 't-99-002'];

var productDescriptions = ['Superslurry electric blender', 'Apple - iPod (second-hand)',     'CoziNap nylon duvet tog 2', 'Headbanger mini hi-fi 20W', 'MagiBoot shoe cleaning kit', 'The PushmiPulu lawnmower'];

var productPrices = [45, 50, 15, 25, 75, 7, 60];

var productStock = [200, 0, 2, 500, 500, 15];

// These are useful variables

var customerIndex;

    
</SCRIPT>

</HEAD>

</HTML>

et voici pour la question 3 le code M150_TMA03_2007J_Q3.HTML
<HTML>
<HEAD>    M150 TMAO3 Question 3
<TITLE>SOFASPEND - IN THE BEST POSSIBLE TASTE!</TITLE>

<SCRIPT

language="JavaScript"
type="text/javascript">    

// These are arrays containing product data

var productDescriptions = ['Superslurry electric blender', 'Apple - iPod (second-hand)',     'CoziNap nylon duvet tog 2', 'Headbanger mini hi-fi 20W', 'MagiBoot shoe cleaning kit', 'The PushmiPulu lawnmower'];

var productPrices = [45, 50, 15, 25, 75, 7];

var productStock = [200, 0, 2, 500, 500, 15];

var receivedLevels = [50, 10, 150, 500, 50, 100];

// Write the function showStockLevels() here

// Write the function addAllReceivedItems() here

// Write the function calculateTotals() here

                
</SCRIPT>

</HEAD>

<FORM NAME = "administrator">

SOFA SPEND plc. CURRENT STOCK LEVELS

Superslurry electric blenders
Current stock

Received:

Apple iPods (second hand)
Current stock

Received:

CoziNap duvets
Current stock

Received:

Headbanger hi-fi
Current stock

Received:

Magiboot cleaning kits
Current stock

Received:

PushmiPulu lawnmowers
Current stock

Received:

</FORM>

<FORM NAME = "statistics">
Total main stock items


Total received stock items

Total number stock items ---  Total value of stock ------- Total tax payable

Press button to calculate .........

</FORM>

</HTML>

Vous me seriez d'un grand secours.
D'avance merci.
Vous pouvez me contactez à regnier.thomas@gmail.com

15 réponses

Messages postés
13616
Date d'inscription
jeudi 13 février 2003
Statut
Membre
Dernière intervention
15 octobre 2013
36
Bonjour,
    souvent on se plaint de n'avoir pas assez d'infos....
    ben là, on a tout !
    bon.. faudrait tout te faire....   mais on on tout....
<hr />                Cordialement            Bul         [mon Site]     [M'écrire]
Messages postés
626
Date d'inscription
samedi 28 septembre 2002
Statut
Membre
Dernière intervention
18 mai 2009
3
Y'a pas une version frenchi ?  ^^'
Messages postés
13616
Date d'inscription
jeudi 13 février 2003
Statut
Membre
Dernière intervention
15 octobre 2013
36
>>

Y'a pas une version frenchi ?
    alors là...  faut pas pousser XtremDuke...
    google, systran, dictionnaire,... je ne vais pas tous les citer !
       m'enfin.. le mieux : c'est ici
<hr />                Cordialement            Bul         [mon Site]     [M'écrire]
Messages postés
19
Date d'inscription
mardi 10 juillet 2007
Statut
Membre
Dernière intervention
24 novembre 2013

bien oui j'ai besoin de tout.
Messages postés
626
Date d'inscription
samedi 28 septembre 2002
Statut
Membre
Dernière intervention
18 mai 2009
3
Traduire l'ennoncé, faire les exercices... J'ai l'impression d'être retourné à l'école :|
Ce que je voulais sous-entendre, c'est qu'il serait peut-être plus judicieux que tu nous donnes tes résultats que qu'on te donne nos avis.

Après ce que j'en dis...
Messages postés
13616
Date d'inscription
jeudi 13 février 2003
Statut
Membre
Dernière intervention
15 octobre 2013
36
>>plus judicieux que tu nous donnes tes résultats et qu'on te donne nos avis
    ben oui....   XtremDuke++:
<hr />                Cordialement            Bul         [mon Site]     [M'écrire]
Messages postés
19
Date d'inscription
mardi 10 juillet 2007
Statut
Membre
Dernière intervention
24 novembre 2013

mon problème c'est que je n'arrive pas à les faire. Je suis entrain d'apprendre et j'aimerais avoir des exemple pour que je puisse mieux comprendre, en plus c'est un vieux cours et il y a des choses dépassée.
J'espérais que vous puissiez m'aidez pour que je puisse avancez la dessus ce weekend.
Messages postés
13616
Date d'inscription
jeudi 13 février 2003
Statut
Membre
Dernière intervention
15 octobre 2013
36
>>

mon problème c'est que je n'arrive pas à les faire.
    on avait bien compris....
    fait ce que tu peux... met ici ce que tu fais....
    ( 1 exemple à la fois ! ), tout le monde t'aidera à mettre au point !
<hr />                Cordialement            Bul         [mon Site]     [M'écrire]
Messages postés
13616
Date d'inscription
jeudi 13 février 2003
Statut
Membre
Dernière intervention
15 octobre 2013
36
>>tout le monde t'aidera à mettre au point
    et t'expliquera ou te renverra vers la documentation nécessaire
<hr />                Cordialement            Bul         [mon Site]     [M'écrire]
Messages postés
19
Date d'inscription
mardi 10 juillet 2007
Statut
Membre
Dernière intervention
24 novembre 2013

ok je vais envoyer les première partie.
Mais pour les questions2 et 3 je n'ai aucune idée de comment je dois commencer
Messages postés
13616
Date d'inscription
jeudi 13 février 2003
Statut
Membre
Dernière intervention
15 octobre 2013
36
>>Mais pour les questions2 et 3 je n'ai aucune idée de comment je dois commencer
    oh.. tu sais, moi je n'ai même pas compris ce qu'il fallait faire.. alors...
    c'est dans un patois auquel j'entrave que dalle...
<hr />                Cordialement            Bul         [mon Site]     [M'écrire]
Messages postés
943
Date d'inscription
mardi 14 novembre 2006
Statut
Membre
Dernière intervention
7 août 2009
3
C'est facile l'anglais suffit de partir vivre quelques temps la bas et hop on parle anglais courament (comme moi :-) ) mais la j'ai pas le temps de traduire si j'ai le temps ce week end je t'aiderai (à traduire le texte, je ne ferais pas l'exercice) mais je ne promet rien.

<hr size="2" width="100%" />
Maelo ou Elo --> Mon blog
Messages postés
13616
Date d'inscription
jeudi 13 février 2003
Statut
Membre
Dernière intervention
15 octobre 2013
36
>>suffit de partir vivre quelques temps la bas
    ah ben non... je ne parle pas la langue   ...pfffff
>>je t'aiderai (à traduire le texte)
    si c'est pour moi... j'ai TAG    ;o))      comme dit au dessus, mais merci maelob...
>>je ne ferais pas l'exercice  
   euh.... je ne pense pas que je le fasse non plus.
<hr />                Cordialement            Bul         [mon Site]     [M'écrire]
Messages postés
943
Date d'inscription
mardi 14 novembre 2006
Statut
Membre
Dernière intervention
7 août 2009
3
>>>>suffit de partir vivre quelques temps la bas
    >>ah ben non... je ne parle pas la langue   ...pfffff
       Justement quand tu pars tu es obligé de parler donc...

Puis pour le reste comme j'ai dis c'est si j'ai le temps ce qui n'est pas sur car ça sera le week end...

<hr size="2" width="100%" />
Maelo ou Elo --> Mon blog
Messages postés
13616
Date d'inscription
jeudi 13 février 2003
Statut
Membre
Dernière intervention
15 octobre 2013
36
second degré maelob...   ( d'ailleurs, le pffff était pour moi )  
<hr />                Cordialement            Bul         [mon Site]     [M'écrire]