Você está na página 1de 5

Instituto Federal do Pará (Campus de Paragominas) – Autoria Web

Aluno (a): Jheniffer da Silva Silva


Matrícula: 20220792412
Turma: TADS – 2022 (TG0793NA)
Professor: Dr. Lennon Sales Furtado
Disciplina: Autoria Web
Período: Terceiro Semestre
Data: 04/05/2023

Prova 2 de Programação Web

1- (1,5 Pontos) Cifra de César, Uma das cifras mais simples e mais conhecidas é uma
cifra de César, também conhecida como cifra de deslocamento. Em uma cifra de
deslocamento, os significados das letras são deslocados por um determinado valor. Um
uso moderno comum é a cifra ROT13, onde os valores das letras são deslocados em 13
lugares. Assim 'A' ↔ 'N', 'B' ↔ 'O' e assim por diante. Escreva uma função que tenha
uma string codificada em ROT13 como entrada e retorne uma string decodificada.
Todas as letras serão maiúsculas. Não transforme qualquer caractere não alfabético (ou
seja, espaços, pontuação), mas passe-os adiante.

function rot13(str) {
return str;
}

// Change the inputs below to test


rot13("GUR DHVPX OEBJA SBK WHZCF BIRE GUR YNML QBT.");

Dica: 1
Use String.charCodeAt () para converter o caractere em inglês para ASCII.
Dica: 2
Use String.fromCharCode () para converter ASCII em inglês.
Dica: 3
Deixe qualquer coisa que não esteja entre A-Z como está.
tente resolver o problema agora

const rot13 = (str) => {

return str.split("").map(item => {


let regex = /[A-Z]/;
if(regex.test(item)) {
let textConvert = item.charCodeAt();
for (let i = 0; i < 13; i++) {
if (textConvert == 90) {
textConvert = 65;
}else{
textConvert ++;
}
}
return String.fromCharCode(textConvert);
}else{
return item;
}
}).join("");
}

//traduzir de decodificada para codificada


let decodificada = prompt("insira uma mensagem DECODIFICADA ")
let codificada = rot13(decodificada);
alert ("Sua mensagem decodificada: " + decodificada + " Sua mensagem
codificada: " + codificada);

//traduzir de codificada para decodificada


/*let codificada = prompt("insira uma mensagem CODIFICADA ")
let decodificada = rot13(codificada);
alert("Sua mensagem codificada: " + codificada + " Sua mensagem
decodificada: " + decodificada);*/

2- Mutações, Retorna true se a string no primeiro elemento da matriz contiver todas as


letras da string no segundo elemento da matriz. Por exemplo, ["hello", "Hello"], deve
retornar true porque todas as letras na segunda string estão presentes na primeira,
ignorando o caso. Os argumentos ["hello", "hey"] devem retornar false porque a string
"hello" não contém um "y". Por fim, ["Alien", "line"], deve retornar true porque todas
as letras em "line" estão presentes em "Alien".

function mutation(arr) {
return arr;
}

mutation(["hello", "hey"]);

Dica: 1
Se tudo estiver em minúsculas, será mais fácil comparar.
Dica: 2
Nossas cordas podem ser mais fáceis de trabalhar se fossem matrizes de caracteres.
Dica: 3
Um loop pode ajudar. Use indexOf () para verificar se a letra da segunda palavra está no
primeiro.

tente resolver o problema agora

function mutation(arr){
var p1 = arr[0];
var p2 = arr[1];
var retorno = true;
for (let i = 0; i < p2.length; i++){
if(p1.indexOf(p2[1]) == -1){
retorno = false;
break;
}
}
return retorno;
}

alert (mutation(["hello", "hey"]));


alert(mutation(["Alien", "line"]));

3- Converter Celsius para Fahrenheit, O algoritmo para converter de Celsius para


Fahrenheit é a temperatura em Celsius vezes 9/5, mais 32. Você recebe uma variável
celsius representando uma temperatura em Celsius. Use a variável fahrenheit já
definida e atribua a temperatura Fahrenheit equivalente à temperatura Celsius
especificada. Use o algoritmo mencionado acima para ajudar a converter a temperatura
Celsius em Fahrenheit.

function convertToF(celsius) {
let fahrenheit;
return fahrenheit;
}

convertToF(30);

Dica:
Tenha em mente a ordem de operação, tente resolver o problema agora

convertToF(celsius){
var fahrenheit = (celsius * 9/5) + 32;
return fahrenheit;
}
var temperaturaCelsius = prompt ("Insira uma temperatura em Celsius:");
var temperaturaFahrenheit = convertToF(temperaturaCelsius);
alert(temperaturaCelsius + " graus celsius equivalem a " + temperaturaFahrenheit + " graus
Fahrenheit " )

4- Confirme o final, Verifique se uma string (primeiro argumento, str) termina com a
string de destino (segundo argumento, destino). Esse desafio pode ser resolvido com o
método .endsWith (), que foi introduzido no ES2015. Mas, para o propósito deste
desafio, gostaríamos que você usasse um dos métodos de substring JavaScript.

function confirmEnding(str, target) {


// "Never give up and good luck will find you."
// -- Falcor
return str;
}

confirmEnding("Bastian", "n");

Bateria de Testes:

confirmEnding("Bastian", "n") should return true.


confirmEnding("Congratulation", "on") should return true.
confirmEnding("Connor", "n") should return false.
confirmEnding("Walking on water and developing software from a
specification are easy if both are frozen", "specification") should
return false.
confirmEnding("He has to give me a new name", "name") should return true.
confirmEnding("Open sesame", "same") should return true.
confirmEnding("Open sesame", "pen") should return false.
confirmEnding("Open sesame", "game") should return false.
confirmEnding("If you want to save our world, you must hurry. We dont
know how much longer we can withstand the nothing", "mountain") should
return false.
confirmEnding("Abstraction", "action") should return true.

function confirmEnding (str, target){


return str.indexOf(target, str.length - target.length) > -1;
}
console.log(confirmEnding("Bastian", "n"));
console.log(confirmEnding("Walking on water and developing software from a
specification are easy if both are frozen", "specification"));
console.log(confirmEnding("Open sesame", "same"));

5- Inverta a string fornecida.Você pode precisar transformar a string em um array antes


de poder reverter isso. Seu resultado deve ser uma string.

function reverseString(str) {
return str;
}

reverseString("hello");
Links Relevantes

     str.split ()
     arr.reverse ()
     arr.join ()

Dica: 1

Comece dividindo a string por caracteres.

Dica: 2

Procure a função interna para inverter uma string.

Dica: 3

Não se esqueça de juntar os caracteres novamente depois de revertê-los.

 tente resolver o problema agora

Bateria de testes:

reverseString("hello") should become "olleh".


reverseString("Howdy") should become "ydwoH".
reverseString("Greetings from Earth") should return "htraE morf
sgniteerG".

function reverseString(str){
var arr = str.split("");
arr.reverse();
var reversedStr = arr.join("");
return reversedStr;
}
var input = prompt("Digite uma palavra para ser invertida");
var reversed = reverseString(input);
alert(reversed);

Você também pode gostar