wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
h1 {{ font-size:98px color:#333; }}
h1 {{ font-size:98px; color:#333; }}
Add semicolon.
CSS
[37, 93, 15
[37, 93, 15]
Close bracket.
Python
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
index = output
index = 'output'
Quote strings.
Python
let s1 = String::from("message"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("message"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
if (y) console.log('yes') else console.log('no')
if (y) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
if (z = 44)
if (z == 44)
Use ==.
C++
for i=1,38 do print(i) end
for i=1,38 do print(i) end
Correct.
Lua
println('value')
println("value")
Double quotes.
Scala
arr[59]
if arr.indices.contains(59) {{ arr[59] }}
Check index.
Swift
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
arr[60]
if (arr.indices.contains(60)) arr[60]
Check index.
Kotlin
class = 'data'
class_name = 'data'
'class' is a keyword.
Python
DELETE FROM orders WHERE age=38
DELETE FROM orders WHERE age=38;
Add semicolon.
SQL
["value", 74]
["value", 74]
Correct.
JSON
$data[70] = 5;
if (isset($data[70])) $data[70] = 5;
Check existence.
PHP
disp('world')
disp('world')
Correct.
MATLAB
if a = 9 then print('world') end
if a == 9 then print('world') end
Use ==.
Lua
<person age=38>
<person age="38">
Quote attribute.
XML
{{'status':'value'}}
{{"status":"value"}}
Use double quotes.
JSON
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
'message' + 100
'message' + str(100)
Can't add int to string.
Python
<user><age>info</age><name>20</name></user
<user><age>info</age><name>20</name></user>
Add closing >.
XML
def compute(foo): return foo + 1
def compute(foo): return foo + 1
Correct.
Python
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
[x*x for x in data if x > 71]
[x*x for x in data if x > 71]
Correct list comprehension.
Python
result = 28
result=28
No spaces.
Shell
if val > 70 puts 'value'
if val > 70 puts 'value' end
Add 'end'.
Ruby
switch(z){{ case 93: break; }}
switch(z){{ case 93: break; default: break; }}
Add default case.
Java
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
cin >> index;
int index; cin >> index;
Declare variable.
C++
let x: number | null = null; x.toFixed(44);
let x: number | null = null; if(x!==null) x.toFixed(44);
Null check.
TypeScript
arr.forEach(function(z) {{ console.log(z); }})
arr.forEach((z) => {{ console.log(z); }})
Arrow functions are cleaner.
JavaScript
let index: i32 = "value";
let index: &str = "value";
Type mismatch.
Rust
if (z = 5) {{}}
if (z === 5) {{}}
Use === for equality.
JavaScript
print 'info'
print('info')
print needs parentheses.
Python
<input type='text' value='message'>
<input type='text' value='message' name='title'>
Add name attribute.
HTML
if z = 34:
if z == 34:
Use == for comparison.
Python
function baz() {{ echo 'result'; }}
function baz() {{ echo 'result'; }}
Correct.
PHP
class User def method end end
class User def method end end
Correct.
Ruby
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
<br></br>
<br>
Self-closing.
HTML
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
val c: Int = 'data'
val c: String = 'data'
Fix type.
Kotlin
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
if val = 17 {{}}
if val == 17 {{}}
Use ==.
Swift
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
function foo() {{ return {{key:'value'}} }}
function foo() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript
function render(result:string){{return result;}} render(12);
function render(result:string){{return result;}} render('message');
Pass correct type.
TypeScript
print('output')
print('output')
Correct.
R
String x = 'hello';
String x = "hello";
Double quotes.
Java
INSERT INTO orders VALUES ('data',1)
INSERT INTO orders (age, role) VALUES ('data',1);
Specify columns.
SQL
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
print 'test'
print 'test';
Add semicolon.
Perl
JOIN profiles ON orders.id = profiles.name
JOIN profiles ON orders.id = profiles.name
Correct.
SQL
<ul><li>hello<li>hello</ul>
<ul><li>hello</li><li>hello</li></ul>
Close li.
HTML
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
<hr></hr>
<hr>
Self-closing.
HTML
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
var x int
var x int
Correct.
Go
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
$result = 26; if ($result = 26) {{}}
$result = 26; if ($result == 26) {{}}
Use ==.
PHP
list[66]
if (length(list) >= 66) list[66]
Check length.
R
// comment
/* comment */
Use /* */.
CSS
if (num = 44) {}
if (num == 44) {}
Use ==.
Dart
void main() {{ print('message') }}
void main() {{ print('message'); }}
Add semicolon.
Dart
List(19,74,10)
List(19,74,10)
Correct.
Scala
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(60);
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(60);
Correct.
Node.js
if [ $bar = 9 ]; then
if [ "$bar" = 9 ]; then
Quote variable.
Shell
'result' + 53
'result' + 53.to_s
Convert int.
Ruby
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
echo 'result'
echo 'result';
Add semicolon.
PHP
if y = 18
if y == 18
Use ==.
Ruby
{ "name": "output" }
{ "name": "output" }
Correct.
JSON
int[] list = new int[14]; list[14] = 5;
int[] list = new int[14]; if (14 < list.length) list[14] = 5;
Check bounds.
Java
object Order {{ def main(args: Array[String]) = println("output") }}
object Order {{ def main(args: Array[String]): Unit = println("output") }}
Add return type Unit.
Scala
int items[14]; items[14]=5;
int items[14]; if(14<14){{}} else items[14]=5;
Bounds check.
C++
if (z = 69)
if (z == 69)
Use ==.
R
<table><tr><td>test<td>hello</tr></table>
<table><tr><td>test</td><td>hello</td></tr></table>
Close td.
HTML
print 'hello'
print('hello')
Parentheses for function call.
Lua
'20' + 11
20 + 11
Avoid string coercion.
JavaScript
let num: number = 'data';
let num: string = 'data';
Fix type.
TypeScript
if (a = 85) {{}}
if (a == 85) {{}}
Use ==.
Java
let bar: Int = 'info'
let bar: String = 'info'
Fix type.
Swift
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
name: result age: 40
name: result age: 40
Correct.
YAML
let a = 18;
let a = 18;
Correct.
JavaScript
<p>value <b>data</p></b>
<p>value <b>data</b></p>
Nest properly.
HTML
if (result = 71)
if (result == 71)
Use ==.
Scala
function compute(count) print(count) end
function compute(count) print(count) end
Correct.
Lua
int temp = 'hello';
String temp = 'hello';
Type mismatch.
Dart
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
let data: number = 'value';
let data: string = 'value';
Fix type.
TypeScript
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js