Loading...

Във форума е въведено ограничение, което позволява на потребителите единствено да разглеждат публикуваните въпроси.

LilianaVelvheva avatar LilianaVelvheva 17 Точки

Защо Judge ми дава 0/100 на задача 02.Pascal or camel case?

Това е моето решение: https://pastebin.com/mqGFH2vx

Ето условието на задачата:

2.Pascal or Camel Case

An HTML file is given and your task is to write a function that takes two string parameters as an input and transforms the first parameter to the type required by the second parameter.

  • The first parameter will be the text that you need to modify depending on the second parameter. The words in it will always be separated by space.
  • The second parameter will be either "Camel Case" or "Pascal Case". In case of different input, your output should be "Error!"

When the button is clicked the function should convert the first string to either of the cases. The output should consist of only one word - the string you have modified. Once your output is done, you should set it as HTML to the <span> element. For more information, see the examples below:

Example

Input

Output

"this is an example", "Camel Case"

thisIsAnExample

"secOND eXamPLE", "Pascal Case"

SecondExample

"Invalid Input", "Another Case"

Error!

Тагове:
0
JavaScript Advanced
Axiomatik avatar Axiomatik 2422 Точки
function solve() {
  const text = document.getElementById("text").value;
  const naming = document.getElementById("naming-convention").value;
  const resultContainer = document.getElementById("result");

  const splitted = text.split(" ");

  // resultString must be assigned with let, otherwise can not be modified
  let resultString = "";

  if (naming == "Pascal Case") {
    for (let i = 0; i < splitted.length; i++) {
      resultString += splitted[i][0].toUpperCase() +
        splitted[i].slice(1, splitted[i].length).toLowerCase();
    }
    // resultContainer must receive final value
    resultContainer.textContent = resultString;
  } else if (naming == "Camel Case") {
    resultString += splitted[0][0].toLowerCase()
      + splitted[0].slice(1, splitted[0].length).toLowerCase();
    for (let i = 1; i < splitted.length; i++) {
      resultString += splitted[i][0].toUpperCase() +
        splitted[i].slice(1, splitted[i].length).toLowerCase();
    }
    // resultContainer must receive final value
    resultContainer.textContent = resultString;
  } else {
    // resultContainer.textContent() = resultString;
    resultContainer.textContent = "Error!";
  }
}

 

0
LilianaVelvheva avatar LilianaVelvheva 17 Точки

Много благодаря.

1
Можем ли да използваме бисквитки?
Ние използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Можете да се съгласите с всички или част от тях.
Назад
Функционални
Използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Използваме „сесийни“ бисквитки, за да Ви идентифицираме временно. Те се пазят само по време на активната употреба на услугите ни. След излизане от приложението, затваряне на браузъра или мобилното устройство, данните се трият. Използваме бисквитки, за да предоставим опцията „Запомни Ме“, която Ви позволява да използвате нашите услуги без да предоставяте потребителско име и парола. Допълнително е възможно да използваме бисквитки за да съхраняваме различни малки настройки, като избор на езика, позиции на менюта и персонализирано съдържание. Използваме бисквитки и за измерване на маркетинговите ни усилия.
Рекламни
Използваме бисквитки, за да измерваме маркетинг ефективността ни, броене на посещения, както и за проследяването дали дадено електронно писмо е било отворено.